1 |
|
2 |
|
3 | var ChildProcess = require('child_process');
|
4 | var Fs = require('fs');
|
5 | var Lab = require('lab');
|
6 | var Path = require('path');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var internals = {};
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | var lab = exports.lab = Lab.script();
|
17 | var expect = Lab.expect;
|
18 | var before = lab.before;
|
19 | var after = lab.after;
|
20 | var describe = lab.experiment;
|
21 | var it = lab.test;
|
22 |
|
23 | describe('Confidence Binary', function () {
|
24 |
|
25 | var confidencePath = Path.join(__dirname, '../', '/bin', '/confidence');
|
26 | var configPath = Path.join(__dirname, '/config.json');
|
27 | var tree = {
|
28 |
|
29 | key1: 'abc',
|
30 | key2: {
|
31 |
|
32 | $filter: 'env',
|
33 | production: {
|
34 |
|
35 | deeper: {
|
36 |
|
37 | $value: 'value'
|
38 | }
|
39 | },
|
40 | $default: {
|
41 |
|
42 | $filter: 'platform',
|
43 | ios: 1,
|
44 | $default: 2
|
45 | }
|
46 | },
|
47 | key3: {
|
48 |
|
49 | sub1: {
|
50 | $value: 0,
|
51 | $meta: 'something'
|
52 | },
|
53 | sub2: {
|
54 |
|
55 | $filter: 'xfactor',
|
56 | $id: 'x_factor',
|
57 | yes: ''
|
58 | }
|
59 | },
|
60 | key4: [12, 13, { $filter: 'none', x: 10, $default: 14 }],
|
61 | key5: {},
|
62 | ab: {
|
63 |
|
64 | $filter: 'random.1',
|
65 | $id: 'random_ab_test',
|
66 | $range: [
|
67 | { limit: 1, value: [1, 2] },
|
68 | { limit: 2, value: { $value: 2 } },
|
69 | { limit: 3, value: { a: 5 }, id: '3' },
|
70 | { limit: 10, value: 4 },
|
71 | { limit: 20, value: 5 }
|
72 | ],
|
73 | $default: 6
|
74 | },
|
75 | $meta: {
|
76 | something: 'else'
|
77 | }
|
78 | };
|
79 |
|
80 | before(function (done) {
|
81 |
|
82 | var stream = Fs.createWriteStream(configPath);
|
83 | stream.write(JSON.stringify(tree));
|
84 | stream.end();
|
85 | done();
|
86 | });
|
87 |
|
88 |
|
89 | after(function (done) {
|
90 |
|
91 | Fs.unlink(configPath, done);
|
92 | });
|
93 |
|
94 | it('generates the correct config', function (done) {
|
95 |
|
96 | var confidence = ChildProcess.spawn('node', [confidencePath, '-c', configPath]);
|
97 |
|
98 | confidence.stdout.on('data', function (data) {
|
99 |
|
100 | var result = data.toString();
|
101 | var obj = JSON.parse('{"key1":"abc","key2":2,"key3":{"sub1":0},"key4":[12,13,14],"key5":{},"ab":6}');
|
102 | expect(result).to.equal(JSON.stringify(obj, null, 4));
|
103 | confidence.kill();
|
104 | done();
|
105 | });
|
106 |
|
107 | confidence.stderr.on('data', function (data) {
|
108 |
|
109 | expect(data.toString()).to.not.exist;
|
110 | });
|
111 | });
|
112 |
|
113 | it('generates the correct config', function (done) {
|
114 |
|
115 | var confidence = ChildProcess.spawn('node', [confidencePath, '-c', configPath, '--filter.env', 'production']);
|
116 |
|
117 | confidence.stdout.on('data', function (data) {
|
118 |
|
119 | var result = data.toString();
|
120 | var obj = JSON.parse('{"key1":"abc","key2":{"deeper":"value"},"key3":{"sub1":0},"key4":[12,13,14],"key5":{},"ab":6}');
|
121 | expect(result).to.equal(JSON.stringify(obj, null, 4));
|
122 | confidence.kill();
|
123 | done();
|
124 | });
|
125 |
|
126 | confidence.stderr.on('data', function (data) {
|
127 |
|
128 | expect(data.toString()).to.not.exist;
|
129 | });
|
130 | });
|
131 | });
|