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

chore: use standard

This commit is contained in:
Ruben Bridgewater
2017-05-06 07:06:52 +02:00
parent 5d29f541e9
commit f1a7bcd735
106 changed files with 10706 additions and 10978 deletions

View File

@@ -1,126 +1,124 @@
'use strict';
'use strict'
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var assert = require('assert')
var config = require('../lib/config')
var helper = require('../helper')
var redis = config.redis
describe("The 'select' method", function () {
describe('The \'select\' method', function () {
helper.allTests(function (ip, args) {
describe('using ' + ip, function () {
describe('when not connected', function () {
var client
helper.allTests(function (ip, args) {
beforeEach(function (done) {
client = redis.createClient.apply(null, args)
client.once('ready', function () {
client.quit()
})
client.on('end', done)
})
describe('using ' + ip, function () {
describe('when not connected', function () {
var client;
it('returns an error if redis is not connected', function (done) {
var buffering = client.select(1, function (err, res) {
assert(err.message.match(/The connection is already closed/))
done()
})
assert(typeof buffering === 'boolean')
})
})
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once('ready', function () {
client.quit();
});
client.on('end', done);
});
describe('when connected', function () {
var client
it('returns an error if redis is not connected', function (done) {
var buffering = client.select(1, function (err, res) {
assert(err.message.match(/The connection is already closed/));
done();
});
assert(typeof buffering === 'boolean');
});
});
beforeEach(function (done) {
client = redis.createClient.apply(null, args)
client.once('ready', function () {
client.flushdb(done)
})
})
describe('when connected', function () {
var client;
afterEach(function () {
client.end(true)
})
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once('ready', function () {
client.flushdb(done);
});
});
it('changes the database and calls the callback', function (done) {
// default value of null means database 0 will be used.
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
var buffering = client.select(1, function (err, res) {
helper.isNotError()(err, res)
assert.strictEqual(client.selectedDb, 1, 'db should be 1 after select')
done()
})
assert(typeof buffering === 'boolean')
})
afterEach(function () {
client.end(true);
});
describe('and a callback is specified', function () {
describe('with a valid db index', function () {
it('selects the appropriate database', function (done) {
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
client.select(1, function (err) {
assert.strictEqual(err, null)
assert.strictEqual(client.selectedDb, 1, 'we should have selected the new valid DB')
done()
})
})
})
it('changes the database and calls the callback', function (done) {
// default value of null means database 0 will be used.
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
var buffering = client.select(1, function (err, res) {
helper.isNotError()(err, res);
assert.strictEqual(client.selectedDb, 1, 'db should be 1 after select');
done();
});
assert(typeof buffering === 'boolean');
});
describe('with an invalid db index', function () {
it('returns an error', function (done) {
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
client.select(9999, function (err) {
assert.strictEqual(err.code, 'ERR')
assert.strictEqual(err.message, 'ERR invalid DB index')
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.selectedDb, undefined, 'default db should be undefined');
client.select(1, function (err) {
assert.equal(err, null);
assert.equal(client.selectedDb, 1, 'we should have selected the new valid DB');
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.selectedDb, undefined, 'default db should be undefined')
client.select(1)
setTimeout(function () {
assert.strictEqual(client.selectedDb, 1, 'we should have selected the new valid DB')
done()
}, 25)
})
})
describe('with an invalid db index', function () {
it('returns an error', function (done) {
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
client.select(9999, function (err) {
assert.equal(err.code, 'ERR');
assert.equal(err.message, 'ERR invalid DB index');
done();
});
});
});
});
describe('with an invalid db index', function () {
it('emits an error when callback not provided', function (done) {
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
describe('and no callback is specified', function () {
describe('with a valid db index', function () {
it('selects the appropriate database', function (done) {
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
client.select(1);
setTimeout(function () {
assert.equal(client.selectedDb, 1, 'we should have selected the new valid DB');
done();
}, 25);
});
});
client.on('error', function (err) {
assert.strictEqual(err.command, 'SELECT')
assert.strictEqual(err.message, 'ERR invalid DB index')
done()
})
describe('with an invalid db index', function () {
it('emits an error when callback not provided', function (done) {
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
client.select(9999)
})
})
})
client.on('error', function (err) {
assert.strictEqual(err.command, 'SELECT');
assert.equal(err.message, 'ERR invalid DB index');
done();
});
client.select(9999);
});
});
});
describe('reconnection occurs', function () {
it('selects the appropriate database after a reconnect', function (done) {
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
client.select(3);
client.set('foo', 'bar', function () {
client.stream.destroy();
});
client.once('ready', function () {
assert.strictEqual(client.selectedDb, 3);
assert(typeof client.serverInfo.db3 === 'object');
done();
});
});
});
});
});
});
});
describe('reconnection occurs', function () {
it('selects the appropriate database after a reconnect', function (done) {
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
client.select(3)
client.set('foo', 'bar', function () {
client.stream.destroy()
})
client.once('ready', function () {
assert.strictEqual(client.selectedDb, 3)
assert(typeof client.serverInfo.db3 === 'object')
done()
})
})
})
})
})
})
})