nconf-test.js
3.92 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
121
122
123
124
125
126
127
128
129
130
131
132
/*
* file-store-test.js: Tests for the nconf File store.
*
* (C) 2011, Charlie Robbins and the Contributors.
*
*/
var fs = require('fs'),
path = require('path'),
vows = require('vows'),
assert = require('assert'),
nconf = require('../lib/nconf'),
data = require('./fixtures/data').data;
vows.describe('nconf').addBatch({
"When using the nconf": {
"should have the correct methods set": function () {
assert.isFunction(nconf.key);
assert.isFunction(nconf.path);
assert.isFunction(nconf.use);
assert.isFunction(nconf.get);
assert.isFunction(nconf.set);
assert.isFunction(nconf.clear);
assert.isFunction(nconf.load);
assert.isFunction(nconf.save);
assert.isFunction(nconf.reset);
},
"the use() method": {
"should instaniate the correct store": function () {
nconf.use('memory');
nconf.load();
assert.instanceOf(nconf.stores['memory'], nconf.Memory);
}
},
"it should": {
topic: function () {
fs.readFile(path.join(__dirname, '..', 'package.json'), this.callback);
},
"have the correct version set": function (err, data) {
assert.isNull(err);
data = JSON.parse(data.toString());
assert.equal(nconf.version, data.version);
}
}
}
}).addBatch({
"When using the nconf": {
"with the memory store": {
"the set() method": {
"should respond with true": function () {
assert.isTrue(nconf.set('foo:bar:bazz', 'buzz'));
}
},
"the get() method": {
"without a callback": {
"should respond with the correct value": function () {
assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
}
},
"with a callback": {
topic: function () {
nconf.get('foo:bar:bazz', this.callback);
},
"should respond with the correct value": function (err, value) {
assert.equal(value, 'buzz');
}
}
}
}
}
}).addBatch({
"When using the nconf": {
"with the memory store": {
"the get() method": {
"should respond allow access to the root": function () {
assert(nconf.get(null));
assert(nconf.get(undefined));
assert(nconf.get());
}
},
"the set() method": {
"should respond allow access to the root and complain about non-objects": function () {
assert(!nconf.set(null, null));
assert(!nconf.set(null, undefined));
assert(!nconf.set(null));
assert(!nconf.set(null, ''));
assert(!nconf.set(null, 1));
var original = nconf.get();
assert(nconf.set(null, nconf.get()));
assert.notEqual(nconf.get(), original);
assert.deepEqual(nconf.get(), original)
}
}
}
}
}).addBatch({
"When using nconf": {
"with the memory store": {
"the clear() method": {
"should respond with the true": function () {
assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
assert.isTrue(nconf.clear('foo:bar:bazz'));
assert.isTrue(typeof nconf.get('foo:bar:bazz') === 'undefined');
}
},
"the load() method": {
"without a callback": {
"should respond with the merged store": function () {
assert.deepEqual(nconf.load(), {
title: 'My specific title',
color: 'green',
movie: 'Kill Bill'
});
}
},
"with a callback": {
topic: function () {
nconf.load(this.callback.bind(null, null));
},
"should respond with the merged store": function (ign, err, store) {
assert.isNull(err);
assert.deepEqual(store, {
title: 'My specific title',
color: 'green',
movie: 'Kill Bill'
});
}
}
}
}
}
}).export(module);