@@ -202,20 +202,31 @@ func TestWhere(t *testing.T) {
202
202
},
203
203
}
204
204
205
- if len (where (containers , "Env.VIRTUAL_HOST" , "demo1.localhost" )) != 1 {
206
- t .Fatalf ("demo1.localhost expected 1 match" )
205
+ tests := []struct {
206
+ tmpl string
207
+ context interface {}
208
+ expected string
209
+ }{
210
+ {`{{where . "Env.VIRTUAL_HOST" "demo1.localhost" | len}}` , containers , `1` },
211
+ {`{{where . "Env.VIRTUAL_HOST" "demo2.localhost" | len}}` , containers , `2` },
212
+ {`{{where . "Env.VIRTUAL_HOST" "demo3.localhost" | len}}` , containers , `1` },
213
+ {`{{where . "Env.NOEXIST" "demo3.localhost" | len}}` , containers , `0` },
207
214
}
208
215
209
- if len ( where ( containers , "Env.VIRTUAL_HOST" , "demo2.localhost" )) != 2 {
210
- t . Fatalf ( "demo2.localhost expected 2 matches" )
211
- }
216
+ for n , test := range tests {
217
+ tmplName := fmt . Sprintf ( "where-test-%d" , n )
218
+ tmpl := template . Must ( newTemplate ( tmplName ). Parse ( test . tmpl ))
212
219
213
- if len (where (containers , "Env.VIRTUAL_HOST" , "demo3.localhost" )) != 1 {
214
- t .Fatalf ("demo3.localhost expected 1 match" )
215
- }
220
+ var b bytes.Buffer
221
+ err := tmpl .ExecuteTemplate (& b , tmplName , test .context )
222
+ if err != nil {
223
+ t .Fatalf ("Error executing template: %v" , err )
224
+ }
216
225
217
- if len (where (containers , "Env.NOEXIST" , "demo3.localhost" )) != 0 {
218
- t .Fatalf ("NOEXIST demo3.localhost expected 0 match" )
226
+ got := b .String ()
227
+ if test .expected != got {
228
+ t .Fatalf ("Incorrect output found; expected %s, got %s" , test .expected , got )
229
+ }
219
230
}
220
231
}
221
232
0 commit comments