mod_serv_http_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package mod_serv_http
  2. import (
  3. "os"
  4. "testing"
  5. "time"
  6. "gitp78su.ipnodns.ru/svi/kern/v2/krn/kctx"
  7. . "gitp78su.ipnodns.ru/svi/kern/v2/krn/ktypes"
  8. "gitp78su.ipnodns.ru/svi/kern/v2/mock/mock_env"
  9. )
  10. type tester struct {
  11. t *testing.T
  12. ctx IKernelCtx
  13. mod IKernelModule
  14. }
  15. func TestModServHttp(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:18301/")
  44. sf.mod = GetModuleServHttp()
  45. _ = GetModuleServHttp()
  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. return
  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. _ = GetModuleServHttp()
  66. }