mod_keeper_test.go 1.8 KB

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