-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
container_test.go
150 lines (113 loc) · 2.57 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package wire_test
import (
"testing"
"github.com/Fs02/wire"
"github.com/stretchr/testify/assert"
)
func TestContainer_Apply_ambiguousConnection(t *testing.T) {
app := wire.New()
app.Connect("LGTM!")
app.Connect(&ComponentA{Value1: "Hi!", Value2: 10})
app.Connect(&ComponentD{})
app.Connect(&ComponentE{})
assert.Panics(t, func() {
app.Apply()
})
}
func TestContainer_Apply_requiresPointerInsteadOfValue(t *testing.T) {
vstring := "LGTM!"
vbool := true
componentB := ComponentB{Value1: []int{1}, Value3: "Hello!"}
componentC := ComponentC{Value3: false}
app := wire.New()
app.Connect(vstring)
app.Connect(vbool)
app.Connect(ComponentA{Value1: "Hi!", Value2: 10})
app.Connect(ComponentA{Value1: "Hello!", Value2: 10}, "hello")
app.Connect(&componentB)
app.Connect(&componentC)
assert.Panics(t, func() {
app.Apply()
})
}
func TestContainer_Apply_missingDependency(t *testing.T) {
componentD := ComponentD{}
app := wire.New()
app.Connect(&componentD)
assert.Panics(t, func() {
app.Apply()
})
}
func TestContainer_Connect_duplicateDependency(t *testing.T) {
componentD := ComponentD{}
app := wire.New()
app.Connect(&componentD)
assert.Panics(t, func() {
app.Connect(&componentD)
})
}
func TestContainer_Connect_cannotWireComponent(t *testing.T) {
componentD := ComponentD{}
app := wire.New()
assert.Panics(t, func() {
app.Connect(componentD)
})
}
func TestContainer_Connect_nilInterface(t *testing.T) {
var a struct {
Value Valuer
}
app := wire.New()
assert.Panics(t, func() {
app.Connect(&a)
})
}
func TestContainer_Connect_nilPointer(t *testing.T) {
var a struct {
Value *int
}
app := wire.New()
assert.Panics(t, func() {
app.Connect(&a)
})
}
func TestContainer_Connect_tagForgotten(t *testing.T) {
var a struct {
Value ComponentA
}
app := wire.New()
app.Connect(ComponentA{})
assert.Panics(t, func() {
app.Connect(&a)
})
}
func TestContainer_Resolve_mustPointer(t *testing.T) {
app := wire.New()
assert.Panics(t, func() {
app.Resolve(ComponentA{})
})
}
func TestContainer_Resolve_typeNotFound(t *testing.T) {
app := wire.New()
assert.Panics(t, func() {
app.Resolve(&ComponentA{}, "notexist")
})
}
func TestContainer_Resolve_nameNotFound(t *testing.T) {
componentA := ComponentA{}
app := wire.New()
app.Connect(&componentA)
app.Apply()
assert.Panics(t, func() {
app.Resolve(&ComponentA{}, "notexist")
})
}
func TestContainer_Resolve_valueAsPointer(t *testing.T) {
app := wire.New()
app.Connect(ComponentA{})
app.Apply()
var resolve *ComponentA
assert.Panics(t, func() {
app.Resolve(&resolve)
})
}