1 | var assert = require('assert')
|
2 |
|
3 | var cccf = require('../index')
|
4 | var config = require('../example.json')
|
5 | var multiple = require('../example-multiple.json')
|
6 |
|
7 | var clone = function(config) { return JSON.parse(JSON.stringify(config)) }
|
8 |
|
9 | describe('Common Container Configuration Format', function() {
|
10 |
|
11 | it('can validate a valid javascript object', function() {
|
12 | assert(cccf.validate(config) == config)
|
13 | })
|
14 |
|
15 | it('can validate a valid json string', function() {
|
16 | assert(typeof cccf.validate(JSON.stringify(config)) == 'object')
|
17 | })
|
18 |
|
19 | it('can validate multiple', function() {
|
20 | assert(cccf.validate(multiple) == multiple)
|
21 | assert(typeof cccf.validate(JSON.stringify(multiple)) == 'object')
|
22 | })
|
23 |
|
24 | it('will not validate ids with invalid chars', function() {
|
25 | var _config = clone(config)
|
26 | _config.id = "yo lo"
|
27 | try { cccf.validate(_config) } catch(e) { assert(e instanceof cccf.exception) }
|
28 | _config.id = "☃"
|
29 | try { cccf.validate(_config) } catch(e) { assert(e instanceof cccf.exception) }
|
30 | })
|
31 |
|
32 | it('will not validate cmd as anything but a string', function() {
|
33 | var _config = clone(config)
|
34 | _config.cmd = 2
|
35 | try { cccf.validate(_config) } catch(e) {
|
36 | assert(e instanceof cccf.exception)
|
37 | assert(e.trace.validation[0].schema.cmd.type == 'string')
|
38 | }
|
39 | })
|
40 |
|
41 | it('will not validate ports as anything but an array', function() {
|
42 | var _config = clone(config)
|
43 | _config.ports = false
|
44 | try { cccf.validate(_config) } catch(e) {
|
45 | assert(e instanceof cccf.exception)
|
46 | assert(e.trace.validation[0].schema.ports.type == 'array')
|
47 | }
|
48 | })
|
49 |
|
50 | it('will not validate badly formatted portmappings', function() {
|
51 | var _config = clone(config)
|
52 | _config.ports = ["80:meh"]
|
53 | try { cccf.validate(_config) } catch(e) { assert(e instanceof cccf.exception) }
|
54 | })
|
55 |
|
56 | it('will not validate env as anything but an array', function() {
|
57 | var _config = clone(config)
|
58 | _config.env = 2
|
59 | try { cccf.validate(_config) } catch(e) {
|
60 | assert(e instanceof cccf.exception)
|
61 | assert(e.trace.validation[0].schema.env.type == 'array')
|
62 | }
|
63 | })
|
64 |
|
65 | it('will not validate badly formatted envs', function() {
|
66 | var _config = clone(config)
|
67 | _config.env = ["FOO:BAR"]
|
68 | try { cccf.validate(_config) } catch(e) { assert(e instanceof cccf.exception) }
|
69 | })
|
70 |
|
71 | it('will validate numbers and dots in env', function() {
|
72 | var _config = clone(config)
|
73 | _config.env = ["FOO=192.168.1.2"]
|
74 | try { cccf.validate(_config) } catch(e) { assert(false) }
|
75 | assert(true)
|
76 | })
|
77 |
|
78 | it('will not validate volumes as anything but an array', function() {
|
79 | var _config = clone(config)
|
80 | _config.volumes = 2
|
81 | try { cccf.validate(_config) } catch(e) {
|
82 | assert(e instanceof cccf.exception)
|
83 | assert(e.trace.validation[0].schema.volumes.type == 'array')
|
84 | }
|
85 | })
|
86 |
|
87 | it('will not validate badly formatted volumes', function() {
|
88 | var _config = clone(config)
|
89 | _config.volumes = ["chili"]
|
90 | try { cccf.validate(_config) } catch(e) { assert(e instanceof cccf.exception) }
|
91 | _config.volumes = ["tmp:tmp"]
|
92 | try { cccf.validate(_config) } catch(e) { assert(e instanceof cccf.exception) }
|
93 | _config.volumes = ["./tmp:/tmp"]
|
94 | try { cccf.validate(_config) } catch(e) { assert(e instanceof cccf.exception) }
|
95 | })
|
96 |
|
97 | it('will not validate expose as anything but an array', function() {
|
98 | var _config = clone(config)
|
99 | _config.expose = 2
|
100 | try { cccf.validate(_config) } catch(e) {
|
101 | assert(e instanceof cccf.exception)
|
102 | assert(e.trace.validation[0].schema.expose.type == 'array')
|
103 | }
|
104 | })
|
105 |
|
106 | it('will not validate badly formatted expose', function() {
|
107 | var _config = clone(config)
|
108 | _config.expose = ["FOO"]
|
109 | try { cccf.validate(_config) } catch(e) { assert(e instanceof cccf.exception) }
|
110 | })
|
111 |
|
112 | it('uses the same schema for mulitple', function() {
|
113 | var _multiple = clone(multiple)
|
114 | _multiple[0].expose = ["FOO"]
|
115 | try { cccf.validate(_multiple) } catch(e) { assert(e instanceof cccf.exception) }
|
116 | })
|
117 |
|
118 | })
|