mod_keeper_test.go 2.0 KB

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