-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer_test.go
53 lines (40 loc) · 1.1 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
package medialocker
import (
"testing"
"github.com/codegangsta/inject"
)
func TestNewContainer(t *testing.T) {
ctx := NewTestAppCtx()
t.Run("works with no args", func(s *testing.T) {
subject := ctx.NewContainer()
if subject == nil {
s.Error("Expected NewContainer to return *Container, got nil!")
}
})
t.Run("it calls the config fn with the injector", func(s *testing.T) {
wasCalledWithInjector := false
configFn := func(_ AppContext, injector inject.Injector) inject.Injector {
if injector != nil {
wasCalledWithInjector = true
}
return injector
}
ctx.NewContainer(configFn)
if !wasCalledWithInjector {
s.Error("Expected config fn to be called with injector, instead was called nil.")
}
})
}
func TestContainer_Inject(t *testing.T) {
subject := NewTestAppCtx().NewContainer(AppContextConfig)
obj := &struct {
Logger *Logger `inject`
}{}
if err := subject.Apply(obj); err != nil {
t.Errorf("Error returned injecting object: %s", err)
}
if obj.Logger == nil {
t.Error("Container injected nil, expected Logger.")
}
obj.Logger.Error("Holy shit, it works.")
}