-
Notifications
You must be signed in to change notification settings - Fork 2
/
nject_test.go
138 lines (123 loc) · 3.76 KB
/
nject_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
package nject
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestAnnotateCacheableProvider(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := Cacheable(Provide("foo", func() { counter++ }))
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).cacheable)
require.True(t, p.(*provider).copy().cacheable)
})
}
func TestAnnotateCacheableSequence(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
c := Cacheable(Sequence("foo", func() { counter++ }))
require.IsType(t, &Collection{}, c)
require.True(t, c.(*Collection).contents[0].cacheable)
})
}
func TestAnnotateCacheableBare(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := Cacheable(func() { counter++ })
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).cacheable)
require.True(t, p.(*provider).copy().cacheable)
})
}
func TestAnnotateNotCacheable(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := NotCacheable(func() { counter++ })
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).notCacheable)
require.True(t, p.(*provider).copy().notCacheable)
})
}
func TestAnnotateMustConsume(t *testing.T) {
wrapTest(t, func(t *testing.T) {
p := MustConsume(func() {})
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).mustConsume)
require.True(t, p.(*provider).copy().mustConsume)
})
}
func TestAnnotateConsumptionOptional(t *testing.T) {
wrapTest(t, func(t *testing.T) {
p := ConsumptionOptional(func() {})
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).consumptionOptional)
require.True(t, p.(*provider).copy().consumptionOptional)
})
}
func TestAnnotateLoose(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := Loose(func() { counter++ })
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).loose)
require.True(t, p.(*provider).copy().loose)
})
}
func TestAnnotateDesired(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := Desired(Provide("foo", func() { counter++ }))
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).desired)
require.True(t, p.(*provider).copy().desired)
})
}
func TestAnnotateRequired(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := Required(Provide("foo", func() { counter++ }))
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).required)
require.True(t, p.(*provider).copy().required)
})
}
func TestAnnotateMustCache(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := MustCache(Provide("foo", func() { counter++ }))
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).mustCache)
require.True(t, p.(*provider).cacheable)
require.True(t, p.(*provider).copy().mustCache)
})
}
func TestAnnotateCombo(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := Required(MustCache(Provide("foo", func() { counter++ })))
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).mustCache)
require.True(t, p.(*provider).cacheable)
require.True(t, p.(*provider).required)
require.True(t, p.(*provider).copy().mustCache)
})
}
func TestAnnotateMemoize(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := Memoize(Provide("foo", func() { counter++ }))
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).memoize)
require.True(t, p.(*provider).cacheable)
require.True(t, p.(*provider).copy().memoize)
})
}
func TestAnnotateCallsinner(t *testing.T) {
wrapTest(t, func(t *testing.T) {
var counter int
p := callsInner(Provide("foo", func() { counter++ }))
require.IsType(t, &provider{}, p)
require.True(t, p.(*provider).callsInner)
require.True(t, p.(*provider).copy().callsInner)
})
}