-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_test.go
69 lines (57 loc) · 1.23 KB
/
module_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
package inversify
import (
"testing"
"github.com/stretchr/testify/suite"
)
type ModuleTestSuite struct {
suite.Suite
}
func getModuleTest1() *Module {
return NewModule("test1").
Register(func(c ContainerBinder) error {
c.Bind(1).ToTypedFactory(func(arg string) (string, error) {
return arg + "hello", nil
}, 0)
return nil
}).
UnRegister(func(c ContainerBinder) error {
c.Unbind(1)
return nil
})
}
func getModuleTest2() *Module {
return NewModule("test2").
Register(func(c ContainerBinder) error {
c.Bind(2).To(" world!!!")
return nil
}).
UnRegister(func(c ContainerBinder) error {
c.Unbind(2)
return nil
})
}
func (t *ModuleTestSuite) TestBasic() {
mdl1 := getModuleTest1()
mdl2 := getModuleTest2()
c := NewContainer("basic")
c.Bind(0).ToTypedFactory(func() (string, error) {
return "Modules, ", nil
})
c.Bind("result").ToTypedFactory(func(a, b string) (string, error) {
return a + b, nil
}, 1, 2)
c.Load(mdl1)
c.Load(mdl2)
c.Build()
val, err := c.Get("result")
t.Equal("Modules, hello world!!!", val)
t.NoError(err)
c.UnLoad(mdl1)
c.UnLoad(mdl2)
c.Unbind("result")
c.Build()
t.False(c.IsBound(1))
}
func TestModuleSuite(t *testing.T) {
suite.Run(t, new(ModuleTestSuite))
}