Skip to content

Commit

Permalink
Test cache misses in persistence-test
Browse files Browse the repository at this point in the history
  • Loading branch information
strugee committed Dec 14, 2017
1 parent a0b0926 commit 4f4cd01
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions test/persistence-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ var vows = require('perjury'),
persistenceutil = require('./lib/persistence'),
wrapFsMocks = persistenceutil.wrapFsMocks;

var getNonexistantKey = {
topic: function(db) {
db.get('lolnope', this.callback);
},
'it worked': function(err) {
assert.ifError(err);
},
'it gave us an empty object': function(err, result) {
assert.isObject(result);
assert.isTrue(_.isEmpty(result));
}
};

var getKey = {
topic: function(db) {
db.get('meaning_of_life', this.callback);
},
'it worked': function(err) {
assert.ifError(err);
},
'it has the value we set': function(err, result) {
assert.isNumber(result);
assert.equal(result, 42);
}
};

vows.describe('persistence module').addBatch({
'When we require the module': {
topic: function() {
Expand Down Expand Up @@ -68,18 +94,7 @@ vows.describe('persistence module').addBatch({
'it works': function(err) {
assert.ifError(err);
},
'and we get the key': {
topic: function(db) {
db.get('meaning_of_life', this.callback);
},
'it worked': function(err) {
assert.ifError(err);
},
'it has the value we set': function(err, result) {
assert.isNumber(result);
assert.equal(result, 42);
}
}
'and we get the key': getKey
},
'and we set a key with a slash': {
topic: function(db) {
Expand All @@ -99,20 +114,19 @@ vows.describe('persistence module').addBatch({
assert.ifError(err);
assert.equal(obj.foo, 'bar');
}
}
},
'and we get a nonexistant key': {
topic: function(db) {
db.get('lolnope', this.callback);
},
'it worked': function(err) {
assert.ifError(err);
},
'it gave us an empty object': function(err, result) {
assert.isObject(result);
assert.isTrue(_.isEmpty(result));
'and we set up a new instance to bust the cache': {
topic: function() {
return require('../lib/persistence')('/tmp')(noopLog);
},
'it worked': function(err) {
assert.ifError(err);
},
'and we get a key': getKey,
'and we get a nonexistant key': getNonexistantKey
}
}
},
'and we get a nonexistant key': getNonexistantKey
})
}
}
Expand Down

0 comments on commit 4f4cd01

Please sign in to comment.