mod_keeper_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package mod_keeper
  2. import (
  3. "os"
  4. "testing"
  5. "time"
  6. "gitp78su.ipnodns.ru/svi/kern/v4/lev1/mock_env"
  7. "gitp78su.ipnodns.ru/svi/kern/v4/lev2/kctx"
  8. "gitp78su.ipnodns.ru/svi/kern/v4/lev2/kspec"
  9. "gitp78su.ipnodns.ru/svi/kern/v4/lev3/mod_spec"
  10. )
  11. const (
  12. baseUrl = "http://localhost:18370/"
  13. pathStore = "/store/store_mod_keeper"
  14. )
  15. type tester struct {
  16. t *testing.T
  17. me *mock_env.MockEnv
  18. kCtx kspec.IKernelCtx
  19. mod mod_spec.IKernelModule
  20. }
  21. func TestModKeeper(t *testing.T) {
  22. sf := &tester{
  23. t: t,
  24. me: mock_env.MakeEnv(),
  25. kCtx: kctx.GetKernelCtx(),
  26. }
  27. _ = os.Unsetenv("LOCAL_STORE_PATH")
  28. _ = os.Setenv("LOCAL_STORE_PATH", pathStore)
  29. _ = os.Unsetenv("LOCAL_HTTP_URL")
  30. _ = os.Setenv("LOCAL_HTTP_URL", baseUrl)
  31. fnClear := func() {
  32. pwd := sf.me.Pwd() + pathStore
  33. _ = os.RemoveAll(pwd)
  34. }
  35. fnClear()
  36. defer fnClear()
  37. sf.kCtx.Set("monolitName", "test_monolit", "test")
  38. sf.new()
  39. sf.done()
  40. }
  41. // Завершение работы.
  42. func (sf *tester) done() {
  43. sf.t.Log("done")
  44. sf.kCtx.Cancel()
  45. sf.kCtx.Wg().Wait()
  46. if isWork := sf.mod.IsWork(); isWork.IsOk() {
  47. sf.t.Fatalf("newGood1(): isWork==true")
  48. }
  49. }
  50. // Создание нового модуля HTTP-сервера.
  51. func (sf *tester) new() {
  52. sf.t.Log("new")
  53. // sf.newBad1()
  54. sf.newGood1()
  55. }
  56. func (sf *tester) newGood1() {
  57. sf.t.Log("newGood1")
  58. _ = mock_env.MakeEnv()
  59. _ = os.Unsetenv("LOCAL_HTTP_URL")
  60. _ = os.Setenv("LOCAL_HTTP_URL", "http://localhost:18320/")
  61. sf.mod = GetModuleKeeper()
  62. _ = GetModuleKeeper()
  63. if sf.mod == nil {
  64. sf.t.Fatalf("newGood1(): mod==nil")
  65. }
  66. go sf.mod.Run()
  67. for {
  68. time.Sleep(time.Millisecond * 1)
  69. if sf.mod.IsWork().IsOk() {
  70. break
  71. }
  72. }
  73. }
  74. // нет ничего для создания модуля
  75. // func (sf *tester) newBad1() {
  76. // sf.t.Log("newBad1")
  77. // defer func() {
  78. // if _panic := recover(); _panic == nil {
  79. // sf.t.Fatalf("newBad1(): panic==nil")
  80. // }
  81. // }()
  82. // _ = GetModuleKeeper()
  83. // }