| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package mod_keeper
- import (
- "context"
- "os"
- "testing"
- "time"
- "gitp78su.ipnodns.ru/svi/kern/v4/d0"
- "gitp78su.ipnodns.ru/svi/kern/v4/d1/mock_env"
- "gitp78su.ipnodns.ru/svi/kern/v4/d3/mod_spec"
- )
- const (
- baseUrl = "http://localhost:18370/"
- pathStore = "/store/store_mod_keeper"
- )
- type tester struct {
- t *testing.T
- me *mock_env.MockEnv
- ctx context.Context
- fnCancel func()
- mod mod_spec.IKernelModule
- owner *d0.LOwner
- }
- func TestModKeeper(t *testing.T) {
- ctx, fnCancel := context.WithCancel(context.Background())
- owner := d0.LetOwner(1, "test_isol_kern_keeper")
- sf := &tester{
- t: t,
- owner: owner,
- me: mock_env.MakeEnv(owner),
- ctx: ctx,
- fnCancel: fnCancel,
- }
- _ = 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().String() + pathStore
- _ = os.RemoveAll(pwd)
- }
- fnClear()
- defer fnClear()
- sf.new()
- sf.done()
- }
- // Завершение работы.
- func (sf *tester) done() {
- sf.t.Log("done")
- sf.fnCancel()
- 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(sf.owner)
- _ = os.Unsetenv("LOCAL_HTTP_URL")
- _ = os.Setenv("LOCAL_HTTP_URL", "http://localhost:18320/")
- sf.mod = GetModuleKeeper()
- _ = GetModuleKeeper()
- 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")
- // }
- // }()
- // _ = GetModuleKeeper()
- // }
|