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,37 +1,37 @@
'use strict'
var Buffer = require('safe-buffer').Buffer
var assert = require('assert')
var config = require('./lib/config')
var helper = require('./helper')
var redis = config.redis
const Buffer = require('safe-buffer').Buffer
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const redis = config.redis
describe('returnBuffers', function () {
helper.allTests(function (ip, basicArgs) {
describe('using ' + ip, function () {
var client
var args = config.configureClient(ip, {
describe('returnBuffers', () => {
helper.allTests((ip, basicArgs) => {
describe(`using ${ip}`, () => {
let client
const args = config.configureClient(ip, {
returnBuffers: true,
detectBuffers: true
})
beforeEach(function (done) {
beforeEach((done) => {
client = redis.createClient.apply(null, args)
var i = 1
let i = 1
if (args[2].detectBuffers) {
// Test if detectBuffer option was deactivated
assert.strictEqual(client.options.detectBuffers, false)
args[2].detectBuffers = false
i++
}
var end = helper.callFuncAfter(done, i)
client.on('warning', function (msg) {
const end = helper.callFuncAfter(done, i)
client.on('warning', (msg) => {
assert.strictEqual(msg, 'WARNING: You activated returnBuffers and detectBuffers at the same time. The return value is always going to be a buffer.')
end()
})
client.once('error', done)
client.once('connect', function () {
client.flushdb(function (err) {
client.once('connect', () => {
client.flushdb((err) => {
client.hmset('hash key 2', 'key 1', 'val 1', 'key 2', 'val 2')
client.set('string key 1', 'string value')
end(err)
@@ -39,18 +39,18 @@ describe('returnBuffers', function () {
})
})
describe('get', function () {
describe('first argument is a string', function () {
it('returns a buffer', function (done) {
client.get('string key 1', function (err, reply) {
describe('get', () => {
describe('first argument is a string', () => {
it('returns a buffer', (done) => {
client.get('string key 1', (err, reply) => {
assert.strictEqual(true, Buffer.isBuffer(reply))
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply.inspect())
return done(err)
})
})
it('returns a bufffer when executed as part of transaction', function (done) {
client.multi().get('string key 1').exec(function (err, reply) {
it('returns a bufffer when executed as part of transaction', (done) => {
client.multi().get('string key 1').exec((err, reply) => {
assert.strictEqual(1, reply.length)
assert.strictEqual(true, Buffer.isBuffer(reply[0]))
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply[0].inspect())
@@ -60,14 +60,14 @@ describe('returnBuffers', function () {
})
})
describe('multi.hget', function () {
it('returns buffers', function (done) {
describe('multi.hget', () => {
it('returns buffers', (done) => {
client.multi()
.hget('hash key 2', 'key 1')
.hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2')
.exec(function (err, reply) {
.exec((err, reply) => {
assert.strictEqual(true, Array.isArray(reply))
assert.strictEqual(4, reply.length)
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect())
@@ -82,14 +82,14 @@ describe('returnBuffers', function () {
})
})
describe('batch.hget', function () {
it('returns buffers', function (done) {
describe('batch.hget', () => {
it('returns buffers', (done) => {
client.batch()
.hget('hash key 2', 'key 1')
.hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2')
.exec(function (err, reply) {
.exec((err, reply) => {
assert.strictEqual(true, Array.isArray(reply))
assert.strictEqual(4, reply.length)
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect())
@@ -104,10 +104,10 @@ describe('returnBuffers', function () {
})
})
describe('hmget', function () {
describe('first argument is a string', function () {
it('handles array of strings with undefined values in transaction (repro #344)', function (done) {
client.multi().hmget('hash key 2', 'key 3', 'key 4').exec(function (err, reply) {
describe('hmget', () => {
describe('first argument is a string', () => {
it('handles array of strings with undefined values in transaction (repro #344)', (done) => {
client.multi().hmget('hash key 2', 'key 3', 'key 4').exec((err, reply) => {
assert.strictEqual(true, Array.isArray(reply))
assert.strictEqual(1, reply.length)
assert.strictEqual(2, reply[0].length)
@@ -118,9 +118,9 @@ describe('returnBuffers', function () {
})
})
describe('first argument is a buffer', function () {
it('returns buffers for keys requested', function (done) {
client.hmget(Buffer.from('hash key 2'), 'key 1', 'key 2', function (err, reply) {
describe('first argument is a buffer', () => {
it('returns buffers for keys requested', (done) => {
client.hmget(Buffer.from('hash key 2'), 'key 1', 'key 2', (err, reply) => {
assert.strictEqual(true, Array.isArray(reply))
assert.strictEqual(2, reply.length)
assert.strictEqual(true, Buffer.isBuffer(reply[0]))
@@ -131,8 +131,8 @@ describe('returnBuffers', function () {
})
})
it('returns buffers for keys requested in transaction', function (done) {
client.multi().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
it('returns buffers for keys requested in transaction', (done) => {
client.multi().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec((err, reply) => {
assert.strictEqual(true, Array.isArray(reply))
assert.strictEqual(1, reply.length)
assert.strictEqual(2, reply[0].length)
@@ -144,8 +144,8 @@ describe('returnBuffers', function () {
})
})
it('returns buffers for keys requested in .batch', function (done) {
client.batch().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
it('returns buffers for keys requested in .batch', (done) => {
client.batch().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec((err, reply) => {
assert.strictEqual(true, Array.isArray(reply))
assert.strictEqual(1, reply.length)
assert.strictEqual(2, reply[0].length)
@@ -159,10 +159,10 @@ describe('returnBuffers', function () {
})
})
describe('hgetall', function (done) {
describe('first argument is a string', function () {
it('returns buffer values', function (done) {
client.hgetall('hash key 2', function (err, reply) {
describe('hgetall', (done) => {
describe('first argument is a string', () => {
it('returns buffer values', (done) => {
client.hgetall('hash key 2', (err, reply) => {
assert.strictEqual('object', typeof reply)
assert.strictEqual(2, Object.keys(reply).length)
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply['key 1'].inspect())
@@ -171,8 +171,8 @@ describe('returnBuffers', function () {
})
})
it('returns buffer values when executed in transaction', function (done) {
client.multi().hgetall('hash key 2').exec(function (err, reply) {
it('returns buffer values when executed in transaction', (done) => {
client.multi().hgetall('hash key 2').exec((err, reply) => {
assert.strictEqual(1, reply.length)
assert.strictEqual('object', typeof reply[0])
assert.strictEqual(2, Object.keys(reply[0]).length)
@@ -182,8 +182,8 @@ describe('returnBuffers', function () {
})
})
it('returns buffer values when executed in .batch', function (done) {
client.batch().hgetall('hash key 2').exec(function (err, reply) {
it('returns buffer values when executed in .batch', (done) => {
client.batch().hgetall('hash key 2').exec((err, reply) => {
assert.strictEqual(1, reply.length)
assert.strictEqual('object', typeof reply[0])
assert.strictEqual(2, Object.keys(reply[0]).length)
@@ -194,9 +194,9 @@ describe('returnBuffers', function () {
})
})
describe('first argument is a buffer', function () {
it('returns buffer values', function (done) {
client.hgetall(Buffer.from('hash key 2'), function (err, reply) {
describe('first argument is a buffer', () => {
it('returns buffer values', (done) => {
client.hgetall(Buffer.from('hash key 2'), (err, reply) => {
assert.strictEqual(null, err)
assert.strictEqual('object', typeof reply)
assert.strictEqual(2, Object.keys(reply).length)
@@ -208,8 +208,8 @@ describe('returnBuffers', function () {
})
})
it('returns buffer values when executed in transaction', function (done) {
client.multi().hgetall(Buffer.from('hash key 2')).exec(function (err, reply) {
it('returns buffer values when executed in transaction', (done) => {
client.multi().hgetall(Buffer.from('hash key 2')).exec((err, reply) => {
assert.strictEqual(1, reply.length)
assert.strictEqual('object', typeof reply[0])
assert.strictEqual(2, Object.keys(reply[0]).length)
@@ -221,8 +221,8 @@ describe('returnBuffers', function () {
})
})
it('returns buffer values when executed in .batch', function (done) {
client.batch().hgetall(Buffer.from('hash key 2')).exec(function (err, reply) {
it('returns buffer values when executed in .batch', (done) => {
client.batch().hgetall(Buffer.from('hash key 2')).exec((err, reply) => {
assert.strictEqual(1, reply.length)
assert.strictEqual('object', typeof reply[0])
assert.strictEqual(2, Object.keys(reply[0]).length)
@@ -236,31 +236,31 @@ describe('returnBuffers', function () {
})
})
describe('publish/subscribe', function (done) {
var pub
var sub
var channel = 'test channel'
var message = Buffer.from('test message')
describe('publish/subscribe', (done) => {
let pub
let sub
const channel = 'test channel'
const message = Buffer.from('test message')
var args = config.configureClient(ip, {
const args = config.configureClient(ip, {
returnBuffers: true
})
beforeEach(function (done) {
var pubConnected
var subConnected
beforeEach((done) => {
let pubConnected
let subConnected
pub = redis.createClient.apply(redis.createClient, basicArgs)
sub = redis.createClient.apply(null, args)
pub.once('connect', function () {
pub.flushdb(function () {
pub.once('connect', () => {
pub.flushdb(() => {
pubConnected = true
if (subConnected) {
done()
}
})
})
sub.once('connect', function () {
sub.once('connect', () => {
subConnected = true
if (pubConnected) {
done()
@@ -268,12 +268,12 @@ describe('returnBuffers', function () {
})
})
it('receives buffer messages', function (done) {
sub.on('subscribe', function (chnl, count) {
it('receives buffer messages', (done) => {
sub.on('subscribe', (chnl, count) => {
pub.publish(channel, message)
})
sub.on('message', function (chnl, msg) {
sub.on('message', (chnl, msg) => {
assert.strictEqual(true, Buffer.isBuffer(msg))
assert.strictEqual('<Buffer 74 65 73 74 20 6d 65 73 73 61 67 65>', msg.inspect())
return done()
@@ -282,7 +282,7 @@ describe('returnBuffers', function () {
sub.subscribe(channel)
})
afterEach(function () {
afterEach(() => {
sub.end(true)
pub.end(true)
})