1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +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,105 +1,94 @@
'use strict';
'use strict'
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var uuid = require('uuid');
var assert = require('assert')
var config = require('../lib/config')
var helper = require('../helper')
var redis = config.redis
var uuid = require('uuid')
describe("The 'flushdb' method", function () {
describe('The \'flushdb\' method', function () {
helper.allTests(function (ip, args) {
describe('using ' + ip, function () {
var key, key2
helper.allTests(function (ip, args) {
beforeEach(function () {
key = uuid.v4()
key2 = uuid.v4()
})
describe('using ' + ip, function () {
var key, key2;
describe('when not connected', function () {
var client
beforeEach(function () {
key = uuid.v4();
key2 = uuid.v4();
});
beforeEach(function (done) {
client = redis.createClient.apply(null, args)
client.once('ready', function () {
client.quit()
})
client.on('end', done)
})
describe('when not connected', function () {
var client;
it('reports an error', function (done) {
client.flushdb(function (err, res) {
assert(err.message.match(/The connection is already closed/))
done()
})
})
})
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('reports an error', function (done) {
client.flushdb(function (err, res) {
assert(err.message.match(/The connection is already closed/));
done();
});
});
});
beforeEach(function (done) {
client = redis.createClient.apply(null, args)
client.once('ready', function () {
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 () {
done();
});
});
describe('when there is data in Redis', function () {
beforeEach(function (done) {
client.mset(key, uuid.v4(), key2, uuid.v4(), helper.isNotError())
client.dbsize([], function (err, res) {
helper.isType.positiveNumber()(err, res)
assert.strictEqual(res, 2, 'Two keys should have been inserted')
done()
})
})
afterEach(function () {
client.end(true);
});
it('deletes all the keys', function (done) {
client.flushdb(function (err, res) {
assert.strictEqual(err, null)
assert.strictEqual(res, 'OK')
client.mget(key, key2, function (err, res) {
assert.strictEqual(null, err, 'Unexpected error returned')
assert.strictEqual(true, Array.isArray(res), 'Results object should be an array.')
assert.strictEqual(2, res.length, 'Results array should have length 2.')
assert.strictEqual(null, res[0], 'Redis key should have been flushed.')
assert.strictEqual(null, res[1], 'Redis key should have been flushed.')
done(err)
})
})
})
describe('when there is data in Redis', function () {
it('results in a db size of zero', function (done) {
client.flushdb(function (err, res) {
assert.strictEqual(err, null)
client.dbsize([], helper.isNumber(0, done))
})
})
beforeEach(function (done) {
client.mset(key, uuid.v4(), key2, uuid.v4(), helper.isNotError());
client.dbsize([], function (err, res) {
helper.isType.positiveNumber()(err, res);
assert.equal(res, 2, 'Two keys should have been inserted');
done();
});
});
it('deletes all the keys', function (done) {
client.flushdb(function (err, res) {
assert.equal(res, 'OK');
client.mget(key, key2, function (err, res) {
assert.strictEqual(null, err, 'Unexpected error returned');
assert.strictEqual(true, Array.isArray(res), 'Results object should be an array.');
assert.strictEqual(2, res.length, 'Results array should have length 2.');
assert.strictEqual(null, res[0], 'Redis key should have been flushed.');
assert.strictEqual(null, res[1], 'Redis key should have been flushed.');
done(err);
});
});
});
it('results in a db size of zero', function (done) {
client.flushdb(function (err, res) {
client.dbsize([], function (err, res) {
helper.isNotError()(err, res);
helper.isType.number()(err, res);
assert.strictEqual(0, res, 'Flushing db should result in db size 0');
done();
});
});
});
it('results in a db size of zero without a callback', function (done) {
client.flushdb();
setTimeout(function (err, res) {
client.dbsize(function (err, res) {
helper.isNotError()(err, res);
helper.isType.number()(err, res);
assert.strictEqual(0, res, 'Flushing db should result in db size 0');
done();
});
}, 25);
});
});
});
});
});
});
it('results in a db size of zero without a callback', function (done) {
client.flushdb()
setTimeout(function () {
client.dbsize(helper.isNumber(0, done))
}, 25)
})
})
})
})
})
})