mod_keeper_test.go 1.4 KB

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