You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
test fixup
This commit is contained in:
@@ -1,89 +1,80 @@
|
||||
'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('The \'hset\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
var hash = 'test hash'
|
||||
describe('The \'hset\' method', () => {
|
||||
helper.allTests((ip, args) => {
|
||||
describe(`using ${ip}`, () => {
|
||||
let client
|
||||
const hash = 'test hash'
|
||||
|
||||
beforeEach(function (done) {
|
||||
beforeEach((done) => {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.once('ready', () => {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows a value to be set in a hash', function (done) {
|
||||
var field = Buffer.from('0123456789')
|
||||
var value = Buffer.from('abcdefghij')
|
||||
it('allows a value to be set in a hash', (done) => {
|
||||
const field = Buffer.from('0123456789')
|
||||
const value = Buffer.from('abcdefghij')
|
||||
|
||||
client.hset(hash, field, value, helper.isNumber(1))
|
||||
client.hget(hash, field, helper.isString(value.toString(), done))
|
||||
})
|
||||
|
||||
it('handles an empty value', function (done) {
|
||||
var field = Buffer.from('0123456789')
|
||||
var value = Buffer.from('')
|
||||
it('handles an empty value', (done) => {
|
||||
const field = Buffer.from('0123456789')
|
||||
const value = Buffer.from('')
|
||||
|
||||
client.hset(hash, field, value, helper.isNumber(1))
|
||||
client.hget([hash, field], helper.isString('', done))
|
||||
})
|
||||
|
||||
it('handles empty key and value', function (done) {
|
||||
var field = Buffer.from('')
|
||||
var value = Buffer.from('')
|
||||
client.hset([hash, field, value], function (err, res) {
|
||||
it('handles empty key and value', (done) => {
|
||||
const field = Buffer.from('')
|
||||
const value = Buffer.from('')
|
||||
client.hset([hash, field, value], (err, res) => {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res, 1)
|
||||
client.hset(hash, field, value, helper.isNumber(0, done))
|
||||
})
|
||||
})
|
||||
|
||||
it('warns if someone passed a array either as field or as value', function (done) {
|
||||
var hash = 'test hash'
|
||||
var field = 'array'
|
||||
it('warns if someone passed a array either as field or as value', (done) => {
|
||||
const hash = 'test hash'
|
||||
const field = 'array'
|
||||
// This would be converted to "array contents" but if you use more than one entry,
|
||||
// it'll result in e.g. "array contents,second content" and this is not supported and considered harmful
|
||||
var value = ['array contents']
|
||||
client.on('warning', function (msg) {
|
||||
assert.strictEqual(
|
||||
msg,
|
||||
'Deprecated: The HMSET command contains a argument of type Array.\n' +
|
||||
'This is converted to "array contents" by using .toString() now and will return an error from v.3.0 on.\n' +
|
||||
'Please handle this in your code to make sure everything works as you intended it to.'
|
||||
)
|
||||
done()
|
||||
})
|
||||
client.hmset(hash, field, value)
|
||||
const value = ['array contents']
|
||||
client.hmset(hash, field, value, helper.isError(done))
|
||||
})
|
||||
|
||||
it('does not error when a buffer and date are set as values on the same hash', function (done) {
|
||||
var hash = 'test hash'
|
||||
var field1 = 'buffer'
|
||||
var value1 = Buffer.from('abcdefghij')
|
||||
var field2 = 'date'
|
||||
var value2 = new Date()
|
||||
it('does not error when a buffer and date are set as values on the same hash', (done) => {
|
||||
const hash = 'test hash'
|
||||
const field1 = 'buffer'
|
||||
const value1 = Buffer.from('abcdefghij')
|
||||
const field2 = 'date'
|
||||
const value2 = new Date()
|
||||
|
||||
client.hmset(hash, field1, value1, field2, value2, helper.isString('OK', done))
|
||||
})
|
||||
|
||||
it('does not error when a buffer and date are set as fields on the same hash', function (done) {
|
||||
var hash = 'test hash'
|
||||
var value1 = 'buffer'
|
||||
var field1 = Buffer.from('abcdefghij')
|
||||
var value2 = 'date'
|
||||
var field2 = new Date()
|
||||
it('does not error when a buffer and date are set as fields on the same hash', (done) => {
|
||||
const hash = 'test hash'
|
||||
const value1 = 'buffer'
|
||||
const field1 = Buffer.from('abcdefghij')
|
||||
const value2 = 'date'
|
||||
const field2 = new Date()
|
||||
|
||||
client.hmset(hash, field1, value1, field2, value2, helper.isString('OK', done))
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(() => {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user