1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

slight refactor from code review

smoke test large list of commands

ported more tests to mocha, some slight cleanup in tests

move sinon and uuid to dev dependencies

finished porting eval tests over to mocha

rebased mocha testing branch with master

ported client and script tests

ported watch tests

ported detect_buffers tests

ported unref tests

ported auth tests over to mocha

ported idle and no_delay tests

ported hlen, hset

continuing marching forward

ported hincrby, sinter, sort, pubsub tests. improved logic in redis-process, I was still occasionally having issues where redis failed to exit.

switch back to default test command

ported del, exists, hlen, keys, randomkey, type

cleanup based on what I've learned so far from refactor. we now start and stop redis less often. moved tests to their final resting place

finished porting node_redis client tests

ported hgetall, mget, msetnx, rename, renamenx, setex, setnx

ported hgetall, mget, msetnx, rename, renamenx, setex, setnx

ported queue tests to mocha

amalgamated some of the helper logic

ported sadd, scard, sismember, srem, utf-8
This commit is contained in:
Benjamin Coe
2015-07-22 20:59:08 -07:00
parent 04fe11b0f5
commit a0832c3744
54 changed files with 3013 additions and 2593 deletions

View File

@@ -0,0 +1,123 @@
var async = require('async');
var assert = require('assert');
var config = require("../lib/config");
var helper = require('../helper');
var redis = config.redis;
describe("The 'select' method", function () {
function removeMochaListener () {
var mochaListener = process.listeners('uncaughtException').pop();
process.removeListener('uncaughtException', mochaListener);
return mochaListener;
}
function allTests(parser, ip) {
var args = config.configureClient(parser, ip);
describe("using " + parser + " and " + ip, function () {
describe("when not connected", function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(redis.createClient, args);
client.once("error", done);
client.once("connect", function () {
client.quit();
});
client.on('end', function () {
return done();
});
});
it("throws an error if redis is not connected", function (done) {
client.select(1, function (err, res) {
assert.equal(err.message, 'Redis connection gone from end event.');
done();
});
});
});
describe("when connected", function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(redis.createClient, args);
client.once("error", done);
client.once("connect", function () { done(); });
});
afterEach(function () {
client.end();
});
it("changes the database and calls the callback", function (done) {
// default value of null means database 0 will be used.
assert.strictEqual(client.selected_db, null, "default db should be null");
client.select(1, function (err, res) {
helper.isNotError()(err, res);
assert.strictEqual(client.selected_db, 1, "db should be 1 after select");
done();
});
});
describe("and a callback is specified", function () {
describe("with a valid db index", function () {
it("selects the appropriate database", function (done) {
assert.strictEqual(client.selected_db, null, "default db should be null");
client.select(1, function () {
assert.equal(client.selected_db, 1, "we should have selected the new valid DB");
return done();
});
});
});
describe("with an invalid db index", function () {
it("emits an error", function (done) {
assert.strictEqual(client.selected_db, null, "default db should be null");
client.select(9999, function (err) {
assert.equal(err.message, 'ERR invalid DB index')
return done();
});
});
});
});
describe("and no callback is specified", function () {
describe("with a valid db index", function () {
it("selects the appropriate database", function (done) {
assert.strictEqual(client.selected_db, null, "default db should be null");
client.select(1);
setTimeout(function () {
assert.equal(client.selected_db, 1, "we should have selected the new valid DB");
return done();
}, 100);
});
});
describe("with an invalid db index", function () {
it("throws an error when callback not provided", function (done) {
var mochaListener = removeMochaListener();
assert.strictEqual(client.selected_db, null, "default db should be null");
process.once('uncaughtException', function (err) {
process.on('uncaughtException', mochaListener);
assert.equal(err.message, 'ERR invalid DB index');
return done();
});
client.select(9999);
});
});
});
});
});
}
['javascript', 'hiredis'].forEach(function (parser) {
allTests(parser, "/tmp/redis.sock");
['IPv4', 'IPv6'].forEach(function (ip) {
allTests(parser, ip);
})
});
});