mod_keeper_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.Txt("monolitName"), "test_monolit", defs.Txt("test"))
  39. sf.new()
  40. sf.done()
  41. }
  42. // Завершение работы.
  43. func (sf *tester) done() {
  44. sf.t.Log("done")
  45. sf.kCtx.Cancel()
  46. sf.kCtx.Wg().Wait()
  47. if isWork := sf.mod.IsWork(); isWork.IsOk() {
  48. sf.t.Fatalf("newGood1(): isWork==true")
  49. }
  50. }
  51. // Создание нового модуля HTTP-сервера.
  52. func (sf *tester) new() {
  53. sf.t.Log("new")
  54. // sf.newBad1()
  55. sf.newGood1()
  56. }
  57. func (sf *tester) newGood1() {
  58. sf.t.Log("newGood1")
  59. _ = mock_env.MakeEnv()
  60. _ = os.Unsetenv("LOCAL_HTTP_URL")
  61. _ = os.Setenv("LOCAL_HTTP_URL", "http://localhost:18320/")
  62. sf.mod = GetModuleKeeper()
  63. _ = GetModuleKeeper()
  64. if sf.mod == nil {
  65. sf.t.Fatalf("newGood1(): mod==nil")
  66. }
  67. go sf.mod.Run()
  68. for {
  69. time.Sleep(time.Millisecond * 1)
  70. if sf.mod.IsWork().IsOk() {
  71. break
  72. }
  73. }
  74. }
  75. // нет ничего для создания модуля
  76. // func (sf *tester) newBad1() {
  77. // sf.t.Log("newBad1")
  78. // defer func() {
  79. // if _panic := recover(); _panic == nil {
  80. // sf.t.Fatalf("newBad1(): panic==nil")
  81. // }
  82. // }()
  83. // _ = GetModuleKeeper()
  84. // }