77 "reflect"
88 "testing"
99 "text/template"
10+
11+ "github.com/stretchr/testify/assert"
1012)
1113
1214type templateTestList []struct {
@@ -38,31 +40,18 @@ func TestContainsString(t *testing.T) {
3840 "PORT" : "1234" ,
3941 }
4042
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" ))
4845}
4946
5047func TestContainsInteger (t * testing.T ) {
5148 env := map [int ]int {
5249 42 : 1234 ,
5350 }
5451
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 ))
6655}
6756
6857func TestKeys (t * testing.T ) {
@@ -105,21 +94,17 @@ func TestKeysNil(t *testing.T) {
10594}
10695
10796func 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" )
11199
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" )
115102
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" )
119105
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" )
123108}
124109
125110func TestGroupByExistingKey (t * testing.T ) {
@@ -144,21 +129,13 @@ func TestGroupByExistingKey(t *testing.T) {
144129 },
145130 }
146131
147- groups , _ := groupBy (containers , "Env.VIRTUAL_HOST" )
148- if len (groups ) != 2 {
149- t .Fail ()
150- }
132+ groups , err := groupBy (containers , "Env.VIRTUAL_HOST" )
151133
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 )
162139}
163140
164141func TestGroupByAfterWhere (t * testing.T ) {
@@ -186,22 +163,13 @@ func TestGroupByAfterWhere(t *testing.T) {
186163 }
187164
188165 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" )
198167
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 )
205173}
206174
207175func TestGroupByLabel (t * testing.T ) {
@@ -236,27 +204,13 @@ func TestGroupByLabel(t *testing.T) {
236204 }
237205
238206 groups , err := groupByLabel (containers , "com.docker.compose.project" )
239- if err != nil {
240- t .FailNow ()
241- }
242207
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 )
260214}
261215
262216func TestGroupByMulti (t * testing.T ) {
0 commit comments