UNPKG

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