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

test fixup

This commit is contained in:
Ruben Bridgewater
2017-05-06 08:16:19 +02:00
parent f1a7bcd735
commit b2613b2270
106 changed files with 2900 additions and 2967 deletions

View File

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