-
Notifications
You must be signed in to change notification settings - Fork 5
/
container_test.go
76 lines (60 loc) · 1.51 KB
/
container_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package pgo2
import (
"fmt"
"reflect"
"testing"
)
type containerTestCommand struct {
Controller
}
func (c *Container) Prepare(a, b string){
fmt.Println("a",a,"b",b)
}
func TestContainer(t *testing.T) {
container := NewContainer("on")
className := container.Bind(&containerTestCommand{})
t.Run("Bind&Has", func(t *testing.T) {
if container.Has(className) == false {
t.FailNow()
}
})
t.Run("GetInfo", func(t *testing.T) {
if info := container.GetInfo(className); info == nil {
t.FailNow()
}
})
t.Run("GetType", func(t *testing.T) {
if container.GetType(className).String() != "pgo2.containerTestCommand" {
t.FailNow()
}
})
t.Run("Get", func(t *testing.T) {
IC := container.Get(className, &Context{}).Interface()
container.Get(className, &Context{}).Interface()
if _, ok := IC.(*containerTestCommand); ok == false {
t.FailNow()
}
})
t.Run("PathList", func(t *testing.T) {
if len(container.PathList("github.com/pinguo/pgo2", "Command")) < 1 {
t.FailNow()
}
})
t.Run("Put", func(t *testing.T) {
rt := reflect.TypeOf(containerTestCommand{})
container.Put(className, reflect.New(rt))
})
t.Run("GetPrepareNoParams", func(t *testing.T) {
IC := container.Get(className, &Context{}).Interface()
if _, ok := IC.(*containerTestCommand); ok == false {
t.FailNow()
}
})
//
t.Run("GetPrepareNoParams", func(t *testing.T) {
IC1 := container.Get(className, &Context{}, "aa","bb").Interface()
if _, ok := IC1.(*containerTestCommand); ok == false {
t.FailNow()
}
})
}