[test] Test saveSync() method of file store

This commit is contained in:
Maciej Małecki 2011-12-25 15:26:04 +01:00
parent cf9889ea81
commit d5ce1ed68f

View file

@ -65,7 +65,11 @@ vows.describe('nconf/stores/file').addBatch({
tmpStore.save(function () {
fs.readFile(tmpStore.file, function (err, d) {
return err ? that.callback(err) : that.callback(err, JSON.parse(d.toString()));
fs.unlinkSync(tmpStore.file);
return err
? that.callback(err)
: that.callback(err, JSON.parse(d.toString()));
});
});
},
@ -75,6 +79,37 @@ vows.describe('nconf/stores/file').addBatch({
}
}
}
}).addBatch({
"When using the nconf file store": {
topic: function () {
var tmpPath = path.join(__dirname, '..', 'fixtures', 'tmp.json'),
tmpStore = new nconf.File({ file: tmpPath });
return tmpStore;
},
"the saveSync() method": {
topic: function (tmpStore) {
var that = this;
Object.keys(data).forEach(function (key) {
tmpStore.set(key, data[key]);
});
tmpStore.saveSync();
fs.readFile(tmpStore.file, function (err, d) {
fs.unlinkSync(tmpStore.file);
return err
? that.callback(err)
: that.callback(err, JSON.parse(d.toString()));
});
},
"should save the data correctly": function (err, read) {
assert.isNull(err);
assert.deepEqual(read, data);
}
}
}
}).addBatch({
"When using the nconf file store": {
"the set() method": {
@ -135,4 +170,5 @@ vows.describe('nconf/stores/file').addBatch({
}
}
}
}).export(module);
}).export(module);