Skip to content

Commit

Permalink
[test] Test saveSync() method of file store
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Dec 25, 2011
1 parent cf9889e commit d5ce1ed
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions test/stores/file-store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
});
});
},
Expand All @@ -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": {
Expand Down Expand Up @@ -135,4 +170,5 @@ vows.describe('nconf/stores/file').addBatch({
}
}
}
}).export(module);
}).export(module);

0 comments on commit d5ce1ed

Please sign in to comment.