90 lines
1.4 KiB
Go
90 lines
1.4 KiB
Go
package system
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func TestCoreInject(t *testing.T) {
|
|
sys := New()
|
|
viper.Set("log.level", 15)
|
|
b1 := EasyBaseService{"b1", []string{}, true}
|
|
b2 := EasyBaseService{"b2", []string{"b1"}, true}
|
|
b3 := EasyBaseService{"b3", []string{"b1"}, true}
|
|
b4 := EasyBaseService{"b4", []string{"b3", "b1"}, true}
|
|
sys.Append(b1, b2, b3, b4)
|
|
sys.Inject(&Inject{
|
|
Dependencies: []string{"b2"},
|
|
MainFunc: func() error { l.Info().Msg("testing, injection"); return nil },
|
|
})
|
|
go sys.Start()
|
|
time.Sleep(time.Second * 1)
|
|
sys.Stop()
|
|
<-sys.Done()
|
|
}
|
|
|
|
func TestTopo(t *testing.T) {
|
|
nodes := []*node{}
|
|
nodes = append(nodes,
|
|
&node{
|
|
name: "n1",
|
|
edge: []string{"n2"},
|
|
},
|
|
&node{
|
|
name: "n2",
|
|
},
|
|
&node{
|
|
name: "n3",
|
|
edge: []string{"n1", "n2"},
|
|
},
|
|
&node{
|
|
name: "n4",
|
|
edge: []string{"n3"},
|
|
},
|
|
&node{
|
|
name: "n5",
|
|
},
|
|
&node{
|
|
name: "n6",
|
|
edge: []string{"n4", "n5"},
|
|
},
|
|
)
|
|
|
|
result := topo(nodes)
|
|
for i := range result {
|
|
fmt.Print(result[i].name, ", ")
|
|
}
|
|
fmt.Print("\n")
|
|
|
|
}
|
|
|
|
func TestTopoError(t *testing.T) {
|
|
nodes := []*node{}
|
|
nodes = append(nodes,
|
|
&node{
|
|
name: "n1",
|
|
edge: []string{"n2"},
|
|
},
|
|
&node{
|
|
name: "n2",
|
|
edge: []string{"n3"},
|
|
},
|
|
)
|
|
|
|
defer func() {
|
|
if r := recover(); r == nil {
|
|
t.Errorf("The code did not panic")
|
|
}
|
|
}()
|
|
|
|
result := topo(nodes)
|
|
for i := range result {
|
|
fmt.Print(result[i].name, ", ")
|
|
}
|
|
fmt.Print("\n")
|
|
|
|
}
|