-
Notifications
You must be signed in to change notification settings - Fork 14
/
dingo_child_test.go
48 lines (36 loc) · 1.01 KB
/
dingo_child_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
package dingo
import (
"testing"
"github.com/stretchr/testify/assert"
)
type (
childIface interface{}
childParentIface interface {
child() childIface
}
childIfaceProvider func() childIface
childParentIfaceImpl struct {
childInstance childIfaceProvider
}
childIfaceImpl struct{}
)
func (i *childParentIfaceImpl) Inject(childInstance childIfaceProvider) {
i.childInstance = childInstance
}
func (i *childParentIfaceImpl) child() childIface {
return i.childInstance()
}
func TestChild(t *testing.T) {
injector, err := NewInjector()
assert.NoError(t, err)
injector.Bind(new(childParentIface)).To(new(childParentIfaceImpl))
child, err := injector.Child()
assert.NoError(t, err)
child.Bind(new(childIface)).To(new(childIfaceImpl))
_, err = injector.GetInstance(new(childParentIface))
assert.NoError(t, err)
// we can get an instance in child, because we have a binding here
i, err := child.GetInstance(new(childParentIface))
assert.NoError(t, err)
assert.NotNil(t, i.(childParentIface).child())
}