7
7
"reflect"
8
8
"testing"
9
9
"text/template"
10
+
11
+ "github.com/stretchr/testify/assert"
10
12
)
11
13
12
14
type templateTestList []struct {
@@ -38,31 +40,18 @@ func TestContainsString(t *testing.T) {
38
40
"PORT" : "1234" ,
39
41
}
40
42
41
- if ! contains (env , "PORT" ) {
42
- t .Fail ()
43
- }
44
-
45
- if contains (env , "MISSING" ) {
46
- t .Fail ()
47
- }
43
+ assert .True (t , contains (env , "PORT" ))
44
+ assert .False (t , contains (env , "MISSING" ))
48
45
}
49
46
50
47
func TestContainsInteger (t * testing.T ) {
51
48
env := map [int ]int {
52
49
42 : 1234 ,
53
50
}
54
51
55
- if ! contains (env , 42 ) {
56
- t .Fail ()
57
- }
58
-
59
- if contains (env , "WRONG TYPE" ) {
60
- t .Fail ()
61
- }
62
-
63
- if contains (env , 24 ) {
64
- t .Fail ()
65
- }
52
+ assert .True (t , contains (env , 42 ))
53
+ assert .False (t , contains (env , "WRONG TYPE" ))
54
+ assert .False (t , contains (env , 24 ))
66
55
}
67
56
68
57
func TestKeys (t * testing.T ) {
@@ -105,21 +94,17 @@ func TestKeysNil(t *testing.T) {
105
94
}
106
95
107
96
func TestIntersect (t * testing.T ) {
108
- if len (intersect ([]string {"foo.fo.com" , "bar.com" }, []string {"foo.bar.com" })) != 0 {
109
- t .Fatal ("Expected no match" )
110
- }
97
+ i := intersect ([]string {"foo.fo.com" , "bar.com" }, []string {"foo.bar.com" })
98
+ assert .Len (t , i , 0 , "Expected no match" )
111
99
112
- if len (intersect ([]string {"foo.fo.com" , "bar.com" }, []string {"bar.com" , "foo.com" })) != 1 {
113
- t .Fatal ("Expected only one match" )
114
- }
100
+ i = intersect ([]string {"foo.fo.com" , "bar.com" }, []string {"bar.com" , "foo.com" })
101
+ assert .Len (t , i , 1 , "Expected exactly one match" )
115
102
116
- if len (intersect ([]string {"foo.com" }, []string {"bar.com" , "foo.com" })) != 1 {
117
- t .Fatal ("Expected only one match" )
118
- }
103
+ i = intersect ([]string {"foo.com" }, []string {"bar.com" , "foo.com" })
104
+ assert .Len (t , i , 1 , "Expected exactly one match" )
119
105
120
- if len (intersect ([]string {"foo.fo.com" , "foo.com" , "bar.com" }, []string {"bar.com" , "foo.com" })) != 2 {
121
- t .Fatal ("Expected two matches" )
122
- }
106
+ i = intersect ([]string {"foo.fo.com" , "foo.com" , "bar.com" }, []string {"bar.com" , "foo.com" })
107
+ assert .Len (t , i , 2 , "Expected exactly two matches" )
123
108
}
124
109
125
110
func TestGroupByExistingKey (t * testing.T ) {
@@ -144,21 +129,13 @@ func TestGroupByExistingKey(t *testing.T) {
144
129
},
145
130
}
146
131
147
- groups , _ := groupBy (containers , "Env.VIRTUAL_HOST" )
148
- if len (groups ) != 2 {
149
- t .Fail ()
150
- }
132
+ groups , err := groupBy (containers , "Env.VIRTUAL_HOST" )
151
133
152
- if len (groups ["demo1.localhost" ]) != 2 {
153
- t .Fail ()
154
- }
155
-
156
- if len (groups ["demo2.localhost" ]) != 1 {
157
- t .FailNow ()
158
- }
159
- if groups ["demo2.localhost" ][0 ].(RuntimeContainer ).ID != "3" {
160
- t .Fail ()
161
- }
134
+ assert .NoError (t , err )
135
+ assert .Len (t , groups , 2 )
136
+ assert .Len (t , groups ["demo1.localhost" ], 2 )
137
+ assert .Len (t , groups ["demo2.localhost" ], 1 )
138
+ assert .Equal (t , "3" , groups ["demo2.localhost" ][0 ].(RuntimeContainer ).ID )
162
139
}
163
140
164
141
func TestGroupByAfterWhere (t * testing.T ) {
@@ -186,22 +163,13 @@ func TestGroupByAfterWhere(t *testing.T) {
186
163
}
187
164
188
165
filtered , _ := where (containers , "Env.EXTERNAL" , "true" )
189
- groups , _ := groupBy (filtered , "Env.VIRTUAL_HOST" )
190
-
191
- if len (groups ) != 2 {
192
- t .Fail ()
193
- }
194
-
195
- if len (groups ["demo1.localhost" ]) != 1 {
196
- t .Fail ()
197
- }
166
+ groups , err := groupBy (filtered , "Env.VIRTUAL_HOST" )
198
167
199
- if len (groups ["demo2.localhost" ]) != 1 {
200
- t .FailNow ()
201
- }
202
- if groups ["demo2.localhost" ][0 ].(RuntimeContainer ).ID != "3" {
203
- t .Fail ()
204
- }
168
+ assert .NoError (t , err )
169
+ assert .Len (t , groups , 2 )
170
+ assert .Len (t , groups ["demo1.localhost" ], 1 )
171
+ assert .Len (t , groups ["demo2.localhost" ], 1 )
172
+ assert .Equal (t , "3" , groups ["demo2.localhost" ][0 ].(RuntimeContainer ).ID )
205
173
}
206
174
207
175
func TestGroupByLabel (t * testing.T ) {
@@ -236,27 +204,13 @@ func TestGroupByLabel(t *testing.T) {
236
204
}
237
205
238
206
groups , err := groupByLabel (containers , "com.docker.compose.project" )
239
- if err != nil {
240
- t .FailNow ()
241
- }
242
207
243
- if len (groups ) != 3 {
244
- t .Fail ()
245
- }
246
-
247
- if len (groups ["one" ]) != 2 {
248
- t .Fail ()
249
- }
250
- if len (groups ["" ]) != 1 {
251
- t .Fail ()
252
- }
253
-
254
- if len (groups ["two" ]) != 1 {
255
- t .FailNow ()
256
- }
257
- if groups ["two" ][0 ].(RuntimeContainer ).ID != "2" {
258
- t .Fail ()
259
- }
208
+ assert .NoError (t , err )
209
+ assert .Len (t , groups , 3 )
210
+ assert .Len (t , groups ["one" ], 2 )
211
+ assert .Len (t , groups ["" ], 1 )
212
+ assert .Len (t , groups ["two" ], 1 )
213
+ assert .Equal (t , "2" , groups ["two" ][0 ].(RuntimeContainer ).ID )
260
214
}
261
215
262
216
func TestGroupByMulti (t * testing.T ) {
0 commit comments