This repository has been archived by the owner on Jan 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 307
/
Copy pathconfig.test.js
106 lines (93 loc) · 2.93 KB
/
config.test.js
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
/**
* Sanity test
* Test must be executed serially as it runs
* against an app instance, this is typically executed by the make file
**/
var rootpath = process.cwd() + '/',
fs = require('fs'),
exec = require('child_process').exec,
path = require('path'),
assert = require('assert'),
sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util"),
should = require('should'),
Config = require('./helpers/require')('core/Configuration');
var defaultConfig = {
"test":"test"
};
/**
* Tests
*/
describe('Calipso config test', function () {
it('I can create a development configuration', function (done) {
mkdir(path.join(rootpath, 'tmp'), function () {
fs.writeFileSync(path.join(rootpath, 'tmp', 'default.json'), JSON.stringify(defaultConfig));
var conf = new Config({env:'development', path:path.join(rootpath, 'tmp')});
conf.type.should.equal('file');
conf.file.should.equal(path.join(rootpath, 'tmp', 'development.json'));
done();
});
});
it('I can add and retrieve configuration', function (done) {
var conf = new Config({env:'development', path:path.join(rootpath, 'tmp')});
conf.init(function () {
conf.set('test:v1', 'v1');
conf.get('test:v1').should.equal('v1');
conf.set('test:v2', 'v2');
conf.get('test:v2').should.equal('v2');
var test = conf.get('test');
test.v1.should.equal('v1');
test.v2.should.equal('v2');
done();
});
});
it('I can use different environments (dev config)', function (done) {
var confDev = new Config({env:'development', path:path.join(rootpath, 'tmp')});
confDev.init(function () {
confDev.set('test:v1', 'v1');
confDev.get('test:v1').should.equal('v1');
confDev.save(function (err) {
(fs.existsSync || path.existsSync)(confDev.file);
done();
});
});
});
it('I can use different environments (test config)', function (done) {
var confTest = new Config({env:'test', path:path.join(rootpath, 'tmp')});
confTest.init(function () {
confTest.set('test:v1', 'v1');
confTest.get('test:v1').should.equal('v1');
confTest.save(function (err) {
(fs.existsSync || path.existsSync)(confTest.file);
done();
});
});
});
it('I can use the setSave shortcut', function (done) {
var conf = new Config({path:path.join(rootpath, 'tmp')});
conf.init(function () {
conf.setSave('test:setsave', 'Yah!', function (err) {
var confTest = new Config({path:path.join(rootpath, 'tmp')});
confTest.init(function () {
confTest.get('test:setsave').should.equal('Yah!');
done();
});
});
});
});
/**
* Mkdir -p.
*
* TODO - these are unix only ...
*
* @param {String} path
* @param {Function} fn
*/
function mkdir(path, fn) {
exec('mkdir -p ' + path, function (err) {
if (err) {
throw err;
}
fn && fn();
});
}
});