4
4
"fmt"
5
5
"os"
6
6
"os/exec"
7
+ "strings"
7
8
8
9
. "gopkg.in/check.v1"
9
10
"path/filepath"
@@ -149,7 +150,6 @@ func (s *RunSuite) TestFieldTypeConversions(c *C) {
149
150
image: tianon/true
150
151
mem_limit: $LIMIT
151
152
memswap_limit: "40000000"
152
- hostname: 100
153
153
` )
154
154
155
155
name := fmt .Sprintf ("%s_%s_1" , p , "test" )
@@ -160,7 +160,6 @@ func (s *RunSuite) TestFieldTypeConversions(c *C) {
160
160
image: tianon/true
161
161
mem_limit: 40000000
162
162
memswap_limit: 40000000
163
- hostname: "100"
164
163
` )
165
164
166
165
name = fmt .Sprintf ("%s_%s_1" , p , "reference" )
@@ -257,5 +256,92 @@ func (s *RunSuite) TestDefaultMultipleComposeFiles(c *C) {
257
256
258
257
c .Assert (container , NotNil )
259
258
}
259
+ }
260
+
261
+ func (s * RunSuite ) TestValidation (c * C ) {
262
+ template := `
263
+ test:
264
+ image: busybox
265
+ ports: invalid_type
266
+ `
267
+ _ , output := s .FromTextCaptureOutput (c , s .RandomProject (), "create" , template )
268
+
269
+ c .Assert (strings .Contains (output , "Service 'test' configuration key 'ports' contains an invalid type, it should be an array." ), Equals , true )
270
+
271
+ template = `
272
+ test:
273
+ image: busybox
274
+ build: .
275
+ `
276
+ _ , output = s .FromTextCaptureOutput (c , s .RandomProject (), "create" , template )
277
+
278
+ c .Assert (strings .Contains (output , "Service 'test' has both an image and build path specified. A service can either be built to image or use an existing image, not both." ), Equals , true )
279
+
280
+ template = `
281
+ test:
282
+ image: busybox
283
+ ports: invalid_type
284
+ links: invalid_type
285
+ devices:
286
+ - /dev/foo:/dev/foo
287
+ - /dev/foo:/dev/foo
288
+ `
289
+ _ , output = s .FromTextCaptureOutput (c , s .RandomProject (), "create" , template )
290
+
291
+ c .Assert (strings .Contains (output , "Service 'test' configuration key 'ports' contains an invalid type, it should be an array." ), Equals , true )
292
+ c .Assert (strings .Contains (output , "Service 'test' configuration key 'links' contains an invalid type, it should be an array" ), Equals , true )
293
+ c .Assert (strings .Contains (output , "Service 'test' configuration key 'devices' value [/dev/foo:/dev/foo /dev/foo:/dev/foo] has non-unique elements" ), Equals , true )
294
+ }
295
+
296
+ func (s * RunSuite ) TestValidationWithExtends (c * C ) {
297
+ template := `
298
+ base:
299
+ image: busybox
300
+ privilege: "something"
301
+ test:
302
+ extends:
303
+ service: base
304
+ `
305
+
306
+ _ , output := s .FromTextCaptureOutput (c , s .RandomProject (), "create" , template )
307
+
308
+ c .Assert (strings .Contains (output , "Unsupported config option for base service: 'privilege' (did you mean 'privileged'?)" ), Equals , true )
309
+
310
+ template = `
311
+ base:
312
+ image: busybox
313
+ test:
314
+ extends:
315
+ service: base
316
+ links: invalid_type
317
+ `
318
+
319
+ _ , output = s .FromTextCaptureOutput (c , s .RandomProject (), "create" , template )
320
+
321
+ c .Assert (strings .Contains (output , "Service 'test' configuration key 'links' contains an invalid type, it should be an array" ), Equals , true )
322
+
323
+ template = `
324
+ test:
325
+ extends:
326
+ file: ./assets/validation/valid/docker-compose.yml
327
+ service: base
328
+ devices:
329
+ - /dev/foo:/dev/foo
330
+ - /dev/foo:/dev/foo
331
+ `
332
+
333
+ _ , output = s .FromTextCaptureOutput (c , s .RandomProject (), "create" , template )
334
+
335
+ c .Assert (strings .Contains (output , "Service 'test' configuration key 'devices' value [/dev/foo:/dev/foo /dev/foo:/dev/foo] has non-unique elements" ), Equals , true )
336
+
337
+ template = `
338
+ test:
339
+ extends:
340
+ file: ./assets/validation/invalid/docker-compose.yml
341
+ service: base
342
+ `
343
+
344
+ _ , output = s .FromTextCaptureOutput (c , s .RandomProject (), "create" , template )
260
345
346
+ c .Assert (strings .Contains (output , "Service 'base' configuration key 'ports' contains an invalid type, it should be an array." ), Equals , true )
261
347
}
0 commit comments