Skip to content

Commit 7b4fcd9

Browse files
committed
Add tests for scanCount option and beforeEach method to reset cache prior to each test.
1 parent 5ad3edb commit 7b4fcd9

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

test/lib/redis-store-spec.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ before(function () {
3535
});
3636
});
3737

38+
beforeEach(function(done) {
39+
redisCache.reset(function() {
40+
done();
41+
});
42+
});
43+
3844
describe ('initialization', function () {
3945

4046
it('should create a store with password instead of auth_pass (auth_pass is deprecated for redis > 2.5)', function (done) {
@@ -359,22 +365,48 @@ describe('ttl', function () {
359365
describe('keys', function () {
360366
it('should return an array of keys for the given pattern', function (done) {
361367
redisCache.set('foo', 'bar', function () {
362-
redisCache.keys('f*', function (err, arrayOfKeys) {
363-
assert.equal(err, null);
364-
assert.notEqual(arrayOfKeys, null);
365-
assert.notEqual(arrayOfKeys.indexOf('foo'), -1);
366-
done();
368+
redisCache.set('far', 'boo', function () {
369+
redisCache.set('faz', 'bam', function () {
370+
redisCache.keys('f*', function (err, arrayOfKeys) {
371+
assert.equal(err, null);
372+
assert.notEqual(arrayOfKeys, null);
373+
assert.notEqual(arrayOfKeys.indexOf('foo'), -1);
374+
assert.equal(arrayOfKeys.length, 3);
375+
done();
376+
});
377+
});
378+
});
379+
});
380+
});
381+
382+
it('should accept a scanCount option', function (done) {
383+
redisCache.set('foo', 'bar', function () {
384+
redisCache.set('far', 'boo', function () {
385+
redisCache.set('faz', 'bam', function () {
386+
redisCache.keys('f*', function (err, arrayOfKeys) {
387+
assert.equal(err, null);
388+
assert.notEqual(arrayOfKeys, null);
389+
assert.notEqual(arrayOfKeys.indexOf('foo'), -1);
390+
assert.equal(arrayOfKeys.length, 3);
391+
done();
392+
});
393+
});
367394
});
368395
});
369396
});
370397

371398
it('should return an array of keys without pattern', function (done) {
372399
redisCache.set('foo', 'bar', function () {
373-
redisCache.keys(function (err, arrayOfKeys) {
374-
assert.equal(err, null);
375-
assert.notEqual(arrayOfKeys, null);
376-
assert.notEqual(arrayOfKeys.indexOf('foo'), -1);
377-
done();
400+
redisCache.set('far', 'boo', function () {
401+
redisCache.set('faz', 'bam', function () {
402+
redisCache.keys(function (err, arrayOfKeys) {
403+
assert.equal(err, null);
404+
assert.notEqual(arrayOfKeys, null);
405+
assert.notEqual(arrayOfKeys.indexOf('foo'), -1);
406+
assert.equal(arrayOfKeys.length, 3);
407+
done();
408+
});
409+
});
378410
});
379411
});
380412
});

0 commit comments

Comments
 (0)