more test fixes

v1.18.x
barisusakli 10 years ago
parent 15d2f54cd0
commit 4554ef2195

@ -76,7 +76,7 @@ describe('List methods', function() {
});
it('should return a list with 2 elements 3, 7', function(done) {
db.getListRange('testList2', 0, -1, function(err, list) {
db.getListRange('testList3', 0, -1, function(err, list) {
assert.equal(err, null);
assert.equal(Array.isArray(list), true);
assert.equal(list.length, 2);
@ -120,11 +120,11 @@ describe('List methods', function() {
});
it('should remove all the matching elements of list', function(done) {
db.listRemoveAll('testList2', '1', function(err) {
db.listRemoveAll('testList5', '1', function(err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
db.getListRange('testList2', 0, -1, function(err, list) {
db.getListRange('testList5', 0, -1, function(err, list) {
assert.equal(Array.isArray(list), true);
assert.equal(list.length, 2);
assert.equal(list.indexOf('1'), -1);
@ -144,12 +144,12 @@ describe('List methods', function() {
return done(err);
}
db.listTrim('testList3', 0, 2, function(err) {
assert.equal(err, null, 'db.listTrim error');
assert.equal(arguments.length, 1, 'arguments.length error');
db.getListRange('testList3', 0, -1, function(err, list) {
assert.equal(list.length, 3, 'list length is not 3');
assert.deepEqual(list, ['1', '2', '3'], 'list not properly trimmed');
db.listTrim('testList6testList6', 0, 2, function(err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
db.getListRange('testList6', 0, -1, function(err, list) {
assert.equal(list.length, 3);
assert.deepEqual(list, ['1', '2', '3']);
done();
});
});

@ -1,11 +1,26 @@
'use strict';
/*global require, after*/
/*global require, after, before*/
var assert = require('assert'),
var async = require('async'),
assert = require('assert'),
db = require('../mocks/databasemock');
describe('Sorted Set methods', function() {
before(function(done) {
async.parallel([
function(next) {
db.sortedSetAdd('sortedSetTest1', [1, 2, 3], ['value1', 'value2', 'value3'], next);
},
function(next) {
db.sortedSetAdd('sortedSetTest2', [1, 4], ['value1', 'value4'], next);
},
function(next) {
db.sortedSetAdd('sortedSetTest3', [2, 4], ['value2', 'value4'], next);
}
], done);
});
describe('sortedSetAdd()', function() {
it('should add an element to a sorted set', function(done) {
db.sortedSetAdd('sorted1', 1, 'value1', function(err) {
@ -22,14 +37,6 @@ describe('Sorted Set methods', function() {
done();
});
});
it('should add four elements to a sorted set', function(done) {
db.sortedSetAdd('sorted3', [2, 3, 4, 5], ['value2', 'value3', 'value4', 'value5'], function(err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
});
});
});
describe('sortedSetsAdd()', function() {
@ -44,7 +51,7 @@ describe('Sorted Set methods', function() {
describe('getSortedSetRange()', function() {
it('should return the lowest scored element', function(done) {
db.getSortedSetRange('sorted2', 0, 0, function(err, value) {
db.getSortedSetRange('sortedSetTest1', 0, 0, function(err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(value, 'value1');
@ -53,7 +60,7 @@ describe('Sorted Set methods', function() {
});
it('should return elements sorted by score lowest to highest', function(done) {
db.getSortedSetRange('sorted2', 0, -1, function(err, values) {
db.getSortedSetRange('sortedSetTest1', 0, -1, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value1', 'value2', 'value3']);
@ -64,7 +71,7 @@ describe('Sorted Set methods', function() {
describe('getSortedSetRevRange()', function() {
it('should return the highest scored element', function(done) {
db.getSortedSetRevRange('sorted2', 0, 0, function(err, value) {
db.getSortedSetRevRange('sortedSetTest1', 0, 0, function(err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(value, 'value3');
@ -73,7 +80,7 @@ describe('Sorted Set methods', function() {
});
it('should return elements sorted by score highest to lowest', function(done) {
db.getSortedSetRevRange('sorted2', 0, -1, function(err, values) {
db.getSortedSetRevRange('sortedSetTest1', 0, -1, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value3', 'value2', 'value1']);
@ -84,7 +91,7 @@ describe('Sorted Set methods', function() {
describe('getSortedSetRangeWithScores()', function() {
it('should return array of elements sorted by score lowest to highest with scores', function(done) {
db.getSortedSetRangeWithScores('sorted2', 0, -1, function(err, values) {
db.getSortedSetRangeWithScores('sortedSetTest1', 0, -1, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value1', score: 1}, {value: 'value2', score: 2}, {value: 'value3', score: 3}]);
@ -95,7 +102,7 @@ describe('Sorted Set methods', function() {
describe('getSortedSetRevRangeWithScores()', function() {
it('should return array of elements sorted by score highest to lowest with scores', function(done) {
db.getSortedSetRevRangeWithScores('sorted2', 0, -1, function(err, values) {
db.getSortedSetRevRangeWithScores('sortedSetTest1', 0, -1, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}, {value: 'value1', score: 1}]);
@ -104,10 +111,9 @@ describe('Sorted Set methods', function() {
});
});
describe('getSortedSetRangeByScore()', function() {
it('should get count elements with score between min max sorted by score lowest to highest', function(done) {
db.getSortedSetRangeByScore('sorted2', 0, -1, '-inf', 2, function(err, values) {
db.getSortedSetRangeByScore('sortedSetTest1', 0, -1, '-inf', 2, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value1', 'value2']);
@ -118,7 +124,7 @@ describe('Sorted Set methods', function() {
describe('getSortedSetRevRangeByScore()', function() {
it('should get count elements with score between max min sorted by score highest to lowest', function(done) {
db.getSortedSetRevRangeByScore('sorted2', 0, -1, '+inf', 2, function(err, values) {
db.getSortedSetRevRangeByScore('sortedSetTest1', 0, -1, '+inf', 2, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value3', 'value2']);
@ -127,10 +133,9 @@ describe('Sorted Set methods', function() {
});
});
describe('getSortedSetRangeByScoreWithScores()', function() {
it('should get count elements with score between min max sorted by score lowest to highest with scores', function(done) {
db.getSortedSetRangeByScoreWithScores('sorted2', 0, -1, '-inf', 2, function(err, values) {
db.getSortedSetRangeByScoreWithScores('sortedSetTest1', 0, -1, '-inf', 2, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value1', score: 1}, {value: 'value2', score: 2}]);
@ -141,7 +146,7 @@ describe('Sorted Set methods', function() {
describe('getSortedSetRevRangeByScoreWithScores()', function() {
it('should get count elements with score between max min sorted by score highest to lowest', function(done) {
db.getSortedSetRevRangeByScoreWithScores('sorted2', 0, -1, '+inf', 2, function(err, values) {
db.getSortedSetRevRangeByScoreWithScores('sortedSetTest1', 0, -1, '+inf', 2, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}]);
@ -161,7 +166,7 @@ describe('Sorted Set methods', function() {
});
it('should return number of elements between scores min max inclusive', function(done) {
db.sortedSetCount('sorted2', '-inf', 2, function(err, count) {
db.sortedSetCount('sortedSetTest1', '-inf', 2, function(err, count) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(count, 2);
@ -181,7 +186,7 @@ describe('Sorted Set methods', function() {
});
it('should return number of elements in a sorted set', function(done) {
db.sortedSetCard('sorted2', function(err, count) {
db.sortedSetCard('sortedSetTest1', function(err, count) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(count, 3);
@ -192,17 +197,17 @@ describe('Sorted Set methods', function() {
describe('sortedSetsCard()', function() {
it('should return the number of elements in sorted sets', function(done) {
db.sortedSetsCard(['sorted1', 'sorted2', 'doesnotexist'], function(err, counts) {
db.sortedSetsCard(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], function(err, counts) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(counts, [2, 3, 0]);
assert.deepEqual(counts, [3, 2, 0]);
done();
});
});
});
describe('sortedSetRank()', function() {
it('should return falsy if sorted set doesnot exist', function(done) {
it('should return falsy if sorted set does not exist', function(done) {
db.sortedSetRank('doesnotexist', 'value1', function(err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
@ -212,7 +217,7 @@ describe('Sorted Set methods', function() {
});
it('should return falsy if element isnt in sorted set', function(done) {
db.sortedSetRank('sorted2', 'value5', function(err, rank) {
db.sortedSetRank('sortedSetTest1', 'value5', function(err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!rank, false);
@ -221,7 +226,7 @@ describe('Sorted Set methods', function() {
});
it('should return the rank of the element in the sorted set sorted by lowest to highest score', function(done) {
db.sortedSetRank('sorted2', 'value1', function(err, rank) {
db.sortedSetRank('sortedSetTest1', 'value1', function(err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(rank, 0);
@ -241,7 +246,7 @@ describe('Sorted Set methods', function() {
});
it('should return falsy if element isnt in sorted set', function(done) {
db.sortedSetRevRank('sorted2', 'value5', function(err, rank) {
db.sortedSetRevRank('sortedSetTest1', 'value5', function(err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!rank, false);
@ -250,7 +255,7 @@ describe('Sorted Set methods', function() {
});
it('should return the rank of the element in the sorted set sorted by highest to lowest score', function(done) {
db.sortedSetRevRank('sorted2', 'value1', function(err, rank) {
db.sortedSetRevRank('sortedSetTest1', 'value1', function(err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(rank, 2);
@ -261,7 +266,7 @@ describe('Sorted Set methods', function() {
describe('sortedSetsRanks()', function() {
it('should return the ranks of values in sorted sets', function(done) {
db.sortedSetsRanks(['sorted1', 'sorted2'], ['value1', 'value2'], function(err, ranks) {
db.sortedSetsRanks(['sortedSetTest1', 'sortedSetTest2'], ['value1', 'value4'], function(err, ranks) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(ranks, [0, 1]);
@ -272,7 +277,7 @@ describe('Sorted Set methods', function() {
describe('sortedSetRanks()', function() {
it('should return the ranks of values in a sorted set', function(done) {
db.sortedSetRanks('sorted2', ['value2', 'value1', 'value3', 'value4'], function(err, ranks) {
db.sortedSetRanks('sortedSetTest1', ['value2', 'value1', 'value3', 'value4'], function(err, ranks) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(ranks, [1, 0, 2, null]);
@ -292,7 +297,7 @@ describe('Sorted Set methods', function() {
});
it('should return falsy if element is not in sorted set', function(done) {
db.sortedSetScore('sorted2', 'value5', function(err, score) {
db.sortedSetScore('sortedSetTest1', 'value5', function(err, score) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!score, false);
@ -301,7 +306,7 @@ describe('Sorted Set methods', function() {
});
it('should return the score of an element', function(done) {
db.sortedSetScore('sorted2', 'value2', function(err, score) {
db.sortedSetScore('sortedSetTest1', 'value2', function(err, score) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(score, 2);
@ -312,10 +317,10 @@ describe('Sorted Set methods', function() {
describe('sortedSetsScore()', function() {
it('should return the scores of value in sorted sets', function(done) {
db.sortedSetsScore(['sorted1', 'sorted2', 'doesnotexist'], 'value2', function(err, scores) {
db.sortedSetsScore(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], 'value1', function(err, scores) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(scores, [null, 2, null]);
assert.deepEqual(scores, [1, 1, null]);
done();
});
});
@ -323,7 +328,7 @@ describe('Sorted Set methods', function() {
describe('sortedSetScores()', function() {
it('should return the scores of value in sorted sets', function(done) {
db.sortedSetScores('sorted2', ['value2', 'value1', 'doesnotexist'], function(err, scores) {
db.sortedSetScores('sortedSetTest1', ['value2', 'value1', 'doesnotexist'], function(err, scores) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(scores, [2, 1, null]);
@ -352,7 +357,7 @@ describe('Sorted Set methods', function() {
});
it('should return true if element is in sorted set', function(done) {
db.isSortedSetMember('sorted2', 'value2', function(err, isMember) {
db.isSortedSetMember('sortedSetTest1', 'value2', function(err, isMember) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(isMember, true);
@ -363,7 +368,7 @@ describe('Sorted Set methods', function() {
describe('isSortedSetMembers()', function() {
it('should return an array of booleans indicating membership', function(done) {
db.isSortedSetMembers('sorted2', ['value1', 'value2', 'value5'], function(err, isMembers) {
db.isSortedSetMembers('sortedSetTest1', ['value1', 'value2', 'value5'], function(err, isMembers) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(isMembers, [true, true, false]);
@ -374,10 +379,10 @@ describe('Sorted Set methods', function() {
describe('getSortedSetUnion()', function() {
it('should return an array of values from both sorted sets sorted by scores lowest to highest', function(done) {
db.getSortedSetUnion(['sorted1', 'sorted3'], 0, -1, function(err, values) {
db.getSortedSetUnion(['sortedSetTest2', 'sortedSetTest3'], 0, -1, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value1', 'value2', 'value4', 'value5', 'value3']);
assert.deepEqual(values, ['value1', 'value2', 'value4']);
done();
});
});
@ -385,10 +390,10 @@ describe('Sorted Set methods', function() {
describe('getSortedSetRevUnion()', function() {
it('should return an array of values from both sorted sets sorted by scores highest to lowest', function(done) {
db.getSortedSetRevUnion(['sorted1', 'sorted3'], 0, -1, function(err, values) {
db.getSortedSetRevUnion(['sortedSetTest2', 'sortedSetTest3'], 0, -1, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value3', 'value5', 'value4', 'value2', 'value1']);
assert.deepEqual(values, ['value4', 'value2', 'value1']);
done();
});
});
@ -424,11 +429,15 @@ describe('Sorted Set methods', function() {
describe('sortedSetRemove()', function() {
before(function(done) {
db.sortedSetAdd('sorted3', [1, 2], ['value1', 'value2'], done);
});
it('should remove an element from a sorted set', function(done) {
db.sortedSetRemove('sorted2', 'value2', function(err) {
db.sortedSetRemove('sorted3', 'value2', function(err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
db.isSortedSetMember('sorted2', 'value2', function(err, isMember) {
db.isSortedSetMember('sorted3', 'value2', function(err, isMember) {
assert.equal(err, null);
assert.equal(isMember, false);
done();
@ -438,11 +447,18 @@ describe('Sorted Set methods', function() {
});
describe('sortedSetsRemove()', function() {
before(function(done) {
async.parallel([
async.apply(db.sortedSetAdd, 'sorted4', [1,2], ['value1', 'value2']),
async.apply(db.sortedSetAdd, 'sorted5', [1,2], ['value1', 'value3']),
], done);
});
it('should remove element from multiple sorted sets', function(done) {
db.sortedSetsRemove(['sorted1', 'sorted2'], 'value1', function(err) {
db.sortedSetsRemove(['sorted4', 'sorted5'], 'value1', function(err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
db.sortedSetsScore(['sorted1', 'sorted2'], 'value1', function(err, scores) {
db.sortedSetsScore(['sorted4', 'sorted5'], 'value1', function(err, scores) {
assert.equal(err, null);
assert.deepEqual(scores, [null, null]);
done();
@ -452,13 +468,17 @@ describe('Sorted Set methods', function() {
});
describe('sortedSetsRemoveRangeByScore()', function() {
before(function(done) {
db.sortedSetAdd('sorted6', [1,2,3,4,5], ['value1','value2','value3','value4','value5'], done);
});
it('should remove elements with scores between min max inclusive', function(done) {
db.sortedSetsRemoveRangeByScore(['sorted3'], 4, 5, function(err) {
db.sortedSetsRemoveRangeByScore(['sorted6'], 4, 5, function(err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
db.getSortedSetRange('sorted3', 0, -1, function(err, values) {
db.getSortedSetRange('sorted6', 0, -1, function(err, values) {
assert.equal(err, null);
assert.deepEqual(values, ['value2', 'value3']);
assert.deepEqual(values, ['value1', 'value2', 'value3']);
done();
});
});

Loading…
Cancel
Save