updated tests to verify that Provider.load respects hierarchy

This commit is contained in:
Jonathan Stewmon 2011-12-19 19:35:20 -06:00 committed by indexzero
parent a216336290
commit fdb73f007b
4 changed files with 47 additions and 16 deletions

View file

@ -18,7 +18,8 @@
"pkginfo": "0.2.x" "pkginfo": "0.2.x"
}, },
"devDependencies": { "devDependencies": {
"vows": "0.6.x" "vows": "0.6.x",
"eyes": "0.1.7"
}, },
"main": "./lib/nconf", "main": "./lib/nconf",
"scripts": { "test": "vows test/*-test.js test/**/*-test.js --spec" }, "scripts": { "test": "vows test/*-test.js test/**/*-test.js --spec" },

View file

@ -1,7 +1,11 @@
{ {
"apples": true, "apples": true,
"bananas": true, "bananas": true,
"foo": {
"bar": "boo"
},
"candy": { "candy": {
"something": "file1",
"something1": true, "something1": true,
"something2": true "something2": true
} }

View file

@ -1,5 +1,6 @@
{ {
"candy": { "candy": {
"something": "file2",
"something3": true, "something3": true,
"something4": true "something4": true
}, },

View file

@ -11,7 +11,8 @@ var assert = require('assert'),
spawn = require('child_process').spawn, spawn = require('child_process').spawn,
vows = require('vows'), vows = require('vows'),
helpers = require('./helpers'), helpers = require('./helpers'),
nconf = require('../lib/nconf'); nconf = require('../lib/nconf'),
eyes = require('eyes');
var fixturesDir = path.join(__dirname, 'fixtures'), var fixturesDir = path.join(__dirname, 'fixtures'),
mergeFixtures = path.join(fixturesDir, 'merge'), mergeFixtures = path.join(fixturesDir, 'merge'),
@ -72,23 +73,47 @@ vows.describe('nconf/provider').addBatch({
provider.load(); provider.load();
provider.merge(override); provider.merge(override);
helpers.assertMerged(null, provider.stores.file.store); helpers.assertMerged(null, provider.stores.file.store);
assert.equal(provider.stores.file.store.candy.something, 'file1');
} }
}, }
"when sources are passed in": { }
topic: new nconf.Provider({ }
sources: { }).addBatch({
user: { "When using nconf": {
type: 'file', "an instance of 'nconf.Provider'": {
file: files[0] "the load() method": {
}, "when sources are passed in": {
global: { topic: new nconf.Provider({
type: 'file', sources: {
file: files[1] user: {
type: 'file',
file: files[0]
},
global: {
type: 'file',
file: files[1]
}
} }
}),
"should respect the hierarchy ": function (provider) {
var merged = provider.load();
helpers.assertMerged(null, merged);
assert.equal(merged.candy.something, 'file1');
console.log(provider.sources);
}
},
"when multiple stores are used": {
topic: new nconf.Provider().overrides({foo: {bar: 'baz'}})
.add('file1', {type: 'file', file: files[0]})
.add('file2', {type: 'file', file: files[1]}),
"should respect the hierarchy": function(provider) {
var merged = provider.load();
helpers.assertMerged(null, merged);
assert.equal(merged.foo.bar, 'baz');
assert.equal(merged.candy.something, 'file1');
} }
}),
"should have the result merged in": function (provider) {
helpers.assertMerged(null, provider.load());
} }
} }
} }