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

Add tests and improve older tests

This commit is contained in:
Ruben Bridgewater
2015-12-30 16:14:23 +01:00
parent 2cd3818ea9
commit 5ef24a90b6
12 changed files with 199 additions and 98 deletions

View File

@@ -37,7 +37,9 @@ describe("The 'select' method", function () {
beforeEach(function (done) {
client = redis.createClient.apply(redis.createClient, args);
client.once("ready", function () { done(); });
client.once("ready", function () {
client.flushdb(done);
});
});
afterEach(function () {
@@ -46,7 +48,7 @@ describe("The 'select' method", function () {
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");
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
var buffering = client.SELECT(1, function (err, res) {
helper.isNotError()(err, res);
assert.strictEqual(client.selected_db, 1, "db should be 1 after select");
@@ -58,7 +60,7 @@ describe("The 'select' method", function () {
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");
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
client.select(1, function (err) {
assert.equal(err, null);
assert.equal(client.selected_db, 1, "we should have selected the new valid DB");
@@ -69,7 +71,7 @@ describe("The 'select' method", function () {
describe("with an invalid db index", function () {
it("returns an error", function (done) {
assert.strictEqual(client.selected_db, null, "default db should be null");
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
client.select(9999, function (err) {
assert.equal(err.code, 'ERR');
assert.equal(err.message, 'ERR invalid DB index');
@@ -82,7 +84,7 @@ describe("The 'select' method", function () {
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");
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
client.select(1);
setTimeout(function () {
assert.equal(client.selected_db, 1, "we should have selected the new valid DB");
@@ -93,7 +95,7 @@ describe("The 'select' method", function () {
describe("with an invalid db index", function () {
it("emits an error when callback not provided", function (done) {
assert.strictEqual(client.selected_db, null, "default db should be null");
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
client.on('error', function (err) {
assert.strictEqual(err.command, 'SELECT');
@@ -105,6 +107,21 @@ describe("The 'select' method", function () {
});
});
});
describe("reconnection occurs", function () {
it("selects the appropriate database after a reconnect", function (done) {
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
client.select(3);
client.set('foo', 'bar', function () {
client.stream.destroy();
});
client.once('ready', function () {
assert.strictEqual(client.selected_db, 3);
assert(typeof client.server_info.db3 === 'object');
done();
});
});
});
});
});
});