forked from golobby/container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
must_test.go
140 lines (103 loc) · 2.9 KB
/
must_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
package container_test
import (
"errors"
"testing"
"github.com/golobby/container/v3"
)
func TestMustSingleton_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
defer func() { recover() }()
container.MustSingleton(c, func() (Shape, error) {
return nil, errors.New("error")
})
t.Errorf("panic expcted.")
}
func TestMustSingletonLazy_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
defer func() { recover() }()
container.MustSingletonLazy(c, func() {})
t.Errorf("panic expcted.")
}
func TestMustNamedSingleton_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
defer func() { recover() }()
container.MustNamedSingleton(c, "name", func() (Shape, error) {
return nil, errors.New("error")
})
t.Errorf("panic expcted.")
}
func TestMustNamedSingletonLazy_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
defer func() { recover() }()
container.MustNamedSingletonLazy(c, "name", func() {})
t.Errorf("panic expcted.")
}
func TestMustTransient_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
defer func() { recover() }()
container.MustTransient(c, func() (Shape, error) {
return nil, errors.New("error")
})
var resVal Shape
container.MustResolve(c, &resVal)
t.Errorf("panic expcted.")
}
func TestMustTransientLazy_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
defer func() { recover() }()
container.MustTransientLazy(c, func() {
})
var resVal Shape
container.MustResolve(c, &resVal)
t.Errorf("panic expcted.")
}
func TestMustNamedTransient_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
defer func() { recover() }()
container.MustNamedTransient(c, "name", func() (Shape, error) {
return nil, errors.New("error")
})
var resVal Shape
container.MustNamedResolve(c, &resVal, "name")
t.Errorf("panic expcted.")
}
func TestMustNamedTransientLazy_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
defer func() { recover() }()
container.MustNamedTransientLazy(c, "name", func() {
})
var resVal Shape
container.MustNamedResolve(c, &resVal, "name")
t.Errorf("panic expcted.")
}
func TestMustCall_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
defer func() { recover() }()
container.MustCall(c, func(s Shape) {
s.GetArea()
})
t.Errorf("panic expcted.")
}
func TestMustResolve_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
var s Shape
defer func() { recover() }()
container.MustResolve(c, &s)
t.Errorf("panic expcted.")
}
func TestMustNamedResolve_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
var s Shape
defer func() { recover() }()
container.MustNamedResolve(c, &s, "name")
t.Errorf("panic expcted.")
}
func TestMustFill_It_Should_Panic_On_Error(t *testing.T) {
c := container.New()
myApp := struct {
S Shape `container:"type"`
}{}
defer func() { recover() }()
container.MustFill(c, &myApp)
t.Errorf("panic expcted.")
}