2011-03-31 06:32:47 +00:00
|
|
|
/*
|
2011-04-02 08:31:20 +00:00
|
|
|
* memory-store-test.js: Tests for the nconf Memory store.
|
2011-03-31 06:32:47 +00:00
|
|
|
*
|
2011-11-24 05:33:08 +00:00
|
|
|
* (C) 2011, Nodejitsu Inc.
|
2011-03-31 06:32:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
var vows = require('vows'),
|
|
|
|
assert = require('assert'),
|
2011-09-19 01:37:01 +00:00
|
|
|
nconf = require('../../lib/nconf'),
|
|
|
|
merge = require('../fixtures/data').merge;
|
2011-06-05 05:29:14 +00:00
|
|
|
|
2011-03-31 06:32:47 +00:00
|
|
|
vows.describe('nconf/stores/memory').addBatch({
|
|
|
|
"When using the nconf memory store": {
|
2011-11-23 02:22:09 +00:00
|
|
|
topic: new nconf.Memory(),
|
2011-03-31 06:32:47 +00:00
|
|
|
"the set() method": {
|
|
|
|
"should respond with true": function (store) {
|
|
|
|
assert.isTrue(store.set('foo:bar:bazz', 'buzz'));
|
2011-05-22 19:30:19 +00:00
|
|
|
assert.isTrue(store.set('falsy:number', 0));
|
|
|
|
assert.isTrue(store.set('falsy:string', ''));
|
|
|
|
assert.isTrue(store.set('falsy:boolean', false));
|
|
|
|
assert.isTrue(store.set('falsy:object', null));
|
2011-03-31 06:32:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"the get() method": {
|
|
|
|
"should respond with the correct value": function (store) {
|
|
|
|
assert.equal(store.get('foo:bar:bazz'), 'buzz');
|
2011-05-22 19:30:19 +00:00
|
|
|
assert.equal(store.get('falsy:number'), 0);
|
|
|
|
assert.equal(store.get('falsy:string'), '');
|
|
|
|
assert.equal(store.get('falsy:boolean'), false);
|
|
|
|
assert.equal(store.get('falsy:object'), null);
|
2011-05-22 20:01:49 +00:00
|
|
|
},
|
|
|
|
"should not fail when retrieving non-existent keys": function (store) {
|
|
|
|
assert.doesNotThrow(function() {
|
|
|
|
assert.equal(store.get('this:key:does:not:exist'), undefined);
|
|
|
|
}, TypeError);
|
|
|
|
},
|
|
|
|
"should not fail when drilling into non-objects": function (store) {
|
|
|
|
assert.doesNotThrow(function() {
|
|
|
|
assert.equal(store.get('falsy:number:uh:oh'), undefined);
|
|
|
|
}, TypeError);
|
2011-03-31 06:32:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"the clear() method": {
|
|
|
|
"should respond with the true": function (store) {
|
|
|
|
assert.equal(store.get('foo:bar:bazz'), 'buzz');
|
|
|
|
assert.isTrue(store.clear('foo:bar:bazz'));
|
|
|
|
assert.isTrue(typeof store.get('foo:bar:bazz') === 'undefined');
|
|
|
|
}
|
2011-06-05 05:29:14 +00:00
|
|
|
},
|
|
|
|
"the merge() method": {
|
|
|
|
"when overriding an existing literal value": function (store) {
|
|
|
|
store.set('merge:literal', 'string-value');
|
|
|
|
store.merge('merge:literal', merge);
|
|
|
|
assert.deepEqual(store.get('merge:literal'), merge);
|
|
|
|
},
|
|
|
|
"when overriding an existing Array value": function (store) {
|
|
|
|
store.set('merge:array', [1,2,3,4]);
|
|
|
|
store.merge('merge:array', merge);
|
|
|
|
assert.deepEqual(store.get('merge:literal'), merge);
|
|
|
|
},
|
|
|
|
"when merging into an existing Object value": function (store) {
|
|
|
|
store.set('merge:object', {
|
|
|
|
prop1: 2,
|
|
|
|
prop2: 'prop2',
|
|
|
|
prop3: {
|
|
|
|
bazz: 'bazz'
|
|
|
|
},
|
|
|
|
prop4: ['foo', 'bar']
|
|
|
|
});
|
|
|
|
store.merge('merge:object', merge);
|
|
|
|
|
|
|
|
assert.equal(store.get('merge:object:prop1'), 1);
|
|
|
|
assert.equal(store.get('merge:object:prop2').length, 3);
|
|
|
|
assert.deepEqual(store.get('merge:object:prop3'), {
|
|
|
|
foo: 'bar',
|
|
|
|
bar: 'foo',
|
|
|
|
bazz: 'bazz'
|
|
|
|
});
|
|
|
|
assert.equal(store.get('merge:object:prop4').length, 2);
|
|
|
|
}
|
2011-03-31 06:32:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).export(module);
|