forked from i-love-flamingo/dingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dingo_setup_test.go
43 lines (36 loc) · 1.07 KB
/
dingo_setup_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
package dingo
import (
"testing"
"github.com/stretchr/testify/assert"
)
type (
setupT1 struct {
member1 string
member2 string
member3 string
Member4 string `inject:"annotation4"`
}
)
func (s *setupT1) Inject(member1 string, annotated *struct {
Member2 string `inject:"annotation2"`
Member3 string `inject:"annotation3"`
}) {
s.member1 = member1
s.member2 = annotated.Member2
s.member3 = annotated.Member3
}
func Test_Dingo_Setup(t *testing.T) {
injector, err := NewInjector()
assert.NoError(t, err)
injector.Bind((*string)(nil)).ToInstance("Member 1")
injector.Bind((*string)(nil)).AnnotatedWith("annotation2").ToInstance("Member 2")
injector.Bind((*string)(nil)).AnnotatedWith("annotation3").ToInstance("Member 3")
injector.Bind((*string)(nil)).AnnotatedWith("annotation4").ToInstance("Member 4")
i, err := injector.GetInstance((*setupT1)(nil))
assert.NoError(t, err)
test := i.(*setupT1)
assert.Equal(t, test.member1, "Member 1")
assert.Equal(t, test.member2, "Member 2")
assert.Equal(t, test.member3, "Member 3")
assert.Equal(t, test.Member4, "Member 4")
}