mod_keeper_test.go 2.0 KB

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