| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package mod_kctx
- import (
- "os"
- "testing"
- "time"
- . "gitp78su.ipnodns.ru/svi/kern/v4/lev0/ktypes"
- "gitp78su.ipnodns.ru/svi/kern/v4/lev1/mock_env"
- "gitp78su.ipnodns.ru/svi/kern/v4/lev2/kctx"
- )
- const (
- baseUrl = "http://localhost:18360/"
- pathStore = "/store/store_kern"
- )
- type tester struct {
- t *testing.T
- me *mock_env.MockEnv
- kCtx IKernelCtx
- mod IKernelModule
- }
- func TestModKernelCtx(t *testing.T) {
- sf := &tester{
- t: t,
- me: mock_env.MakeEnv(),
- kCtx: kctx.GetKernelCtx(),
- }
- _ = os.Unsetenv("LOCAL_STORE_PATH")
- _ = os.Setenv("LOCAL_STORE_PATH", pathStore)
- _ = os.Unsetenv("LOCAL_HTTP_URL")
- _ = os.Setenv("LOCAL_HTTP_URL", baseUrl)
- fnClear := func() {
- pwd := sf.me.Pwd() + pathStore
- _ = os.RemoveAll(pwd)
- }
- fnClear()
- defer fnClear()
- sf.kCtx.Set("monolitName", "test_monolit", "test")
- sf.new()
- sf.done()
- }
- // Завершение работы.
- func (sf *tester) done() {
- sf.t.Log("done")
- sf.kCtx.Cancel()
- sf.kCtx.Wg().Wait()
- if isWork := sf.mod.IsWork(); isWork {
- sf.t.Fatalf("newGood1(): isWork==true")
- }
- }
- // Создание нового модуля HTTP-сервера.
- func (sf *tester) new() {
- sf.t.Log("new")
- // sf.newBad1()
- sf.newGood1()
- }
- func (sf *tester) newGood1() {
- sf.t.Log("newGood1")
- _ = mock_env.MakeEnv()
- _ = os.Unsetenv("LOCAL_HTTP_URL")
- _ = os.Setenv("LOCAL_HTTP_URL", "http://localhost:18328/")
- sf.mod = GetModuleKernelCtx()
- _ = GetModuleKernelCtx()
- if sf.mod == nil {
- sf.t.Fatalf("newGood1(): mod==nil")
- }
- go sf.mod.Run()
- for {
- time.Sleep(time.Millisecond * 1)
- if sf.mod.IsWork() {
- break
- }
- }
- }
- // нет ничего для создания модуля
- // func (sf *tester) newBad1() {
- // sf.t.Log("newBad1")
- // defer func() {
- // if _panic := recover(); _panic == nil {
- // sf.t.Fatalf("newBad1(): panic==nil")
- // }
- // }()
- // _ = GetModuleKernelCtx()
- // }
|