-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathjson_validation.mocha.js
More file actions
120 lines (101 loc) · 3.53 KB
/
json_validation.mocha.js
File metadata and controls
120 lines (101 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var should = require('should');
var Config = require('../../lib/tools/Config');
var Schema = require('../../lib/API/schema.json');
// Change to current folder
process.chdir(__dirname);
describe('JSON validation tests', function() {
it('should fail when passing wrong json', function() {
var ret = Config.validateJSON({
"exec_interpreter" : "node",
"exec_mode" : "clusasdter_mode",
"instances" : "max",
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"max_memory_restart" : "160",
"merge_logs" : true,
"name" : "hapi_playground",
"script" : "chidld.js",
"cwd" : "examadsples",
"node_args" : "--harmoasdny",
"ignore_watch" : ["[\\/\\\\]\\./", "log"],
"watch" : "true"
});
/**
* Error about instances to not be an integer
* Error about watch to not be a boolean
*/
ret.errors.length.should.eql(2);
});
it('should succeed while passing right json', function() {
var ret = Config.validateJSON({
"exec_interpreter" : "node",
"exec_mode" : "cluster_mode",
"instances" : 0,
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"max_memory_restart" : "160",
"merge_logs" : true,
"error_file" : "err.file",
"out_file" : "out.file",
"pid_file" : "pid.file",
"log_file" : "my-merged-log-file.log",
"name" : "hapi_playground",
"script" : "child.js",
"cwd" : "examples",
"node_args" : "--harmony",
"max_memory_restart" : "10M",
"ignore_watch" : ["[\\/\\\\]\\./", "log"],
"watch" : true,
"node_args" : ["hey","hay"],
"env" : {}
});
ret.errors.length.should.eql(0);
});
it('should set default values if some attributes not defined', function(done) {
var default_values = Object.keys(Schema).filter(function(attr) {
if (Schema[attr].default) return Schema[attr].default;
return false;
});
var ret = Config.validateJSON({
script : 'test.js',
name : 'toto'
});
// Returned array should contain also default values
Object.keys(ret.config).should.containDeep(default_values);
done();
});
it('should split args string containing dashed flags (regression #6031)', function() {
var ret = Config.validateJSON({
script: 'app.js',
name: 'app',
args: 'start -c /app/nuxt.config.ts'
});
ret.errors.length.should.eql(0);
ret.config.args.should.eql(['start', '-c', '/app/nuxt.config.ts']);
});
it('should preserve quoted args when splitting string args', function() {
var ret = Config.validateJSON({
script: 'app.js',
name: 'app',
args: 'run --message "hello world" --single \'foo bar\' --another="baz qux"'
});
ret.errors.length.should.eql(0);
ret.config.args.should.eql([
'run',
'--message',
'hello world',
'--single',
'foo bar',
'--another=\"baz qux\"'
]);
});
it('should split node_args string into array', function() {
const cli = '--max-old-space-size=4096 --use-openssl-ca';
const expected = ['--max-old-space-size=4096', '--use-openssl-ca'];
const ret=Config.validateJSON({
script: 'app.js',
name: 'split-test',
node_args: cli
});
ret.errors.length.should.eql(0);
ret.config.node_args.should.eql(expected);
});
});