You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
slight refactor from code review
smoke test large list of commands ported more tests to mocha, some slight cleanup in tests move sinon and uuid to dev dependencies finished porting eval tests over to mocha rebased mocha testing branch with master ported client and script tests ported watch tests ported detect_buffers tests ported unref tests ported auth tests over to mocha ported idle and no_delay tests ported hlen, hset continuing marching forward ported hincrby, sinter, sort, pubsub tests. improved logic in redis-process, I was still occasionally having issues where redis failed to exit. switch back to default test command ported del, exists, hlen, keys, randomkey, type cleanup based on what I've learned so far from refactor. we now start and stop redis less often. moved tests to their final resting place finished porting node_redis client tests ported hgetall, mget, msetnx, rename, renamenx, setex, setnx ported hgetall, mget, msetnx, rename, renamenx, setex, setnx ported queue tests to mocha amalgamated some of the helper logic ported sadd, scard, sismember, srem, utf-8
This commit is contained in:
168
test/commands/mset.spec.js
Normal file
168
test/commands/mset.spec.js
Normal file
@@ -0,0 +1,168 @@
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var config = require("../lib/config");
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var uuid = require('uuid');
|
||||
|
||||
describe("The 'mset' method", function () {
|
||||
|
||||
function removeMochaListener () {
|
||||
var mochaListener = process.listeners('uncaughtException').pop();
|
||||
process.removeListener('uncaughtException', mochaListener);
|
||||
return mochaListener;
|
||||
}
|
||||
|
||||
function allTests(parser, ip) {
|
||||
var args = config.configureClient(parser, ip);
|
||||
|
||||
describe("using " + parser + " and " + ip, function () {
|
||||
var key, value, key2, value2;
|
||||
|
||||
beforeEach(function () {
|
||||
key = uuid.v4();
|
||||
value = uuid.v4();
|
||||
key2 = uuid.v4();
|
||||
value2 = uuid.v4();
|
||||
});
|
||||
|
||||
describe("when not connected", function () {
|
||||
var client;
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(redis.createClient, args);
|
||||
client.once("error", done);
|
||||
client.once("connect", function () {
|
||||
client.quit();
|
||||
});
|
||||
client.on('end', function () {
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("reports an error", function (done) {
|
||||
client.mset(key, value, key2, value2, function (err, res) {
|
||||
assert.equal(err.message, 'Redis connection gone from end event.');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when connected", function () {
|
||||
var client;
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(redis.createClient, args);
|
||||
client.once("error", done);
|
||||
client.once("connect", function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end();
|
||||
});
|
||||
|
||||
describe("and a callback is specified", function () {
|
||||
describe("with valid parameters", function () {
|
||||
it("sets the value correctly", function (done) {
|
||||
client.mset(key, value, key2, value2, function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
async.parallel([function (next) {
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value)(err, res);
|
||||
next();
|
||||
});
|
||||
}, function (next) {
|
||||
client.get(key2, function (err, res) {
|
||||
helper.isString(value2)(err, res);
|
||||
next();
|
||||
});
|
||||
}], function (err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("with undefined 'key' parameter and missing 'value' parameter", function () {
|
||||
it("reports an error", function (done) {
|
||||
client.mset(undefined, function (err, res) {
|
||||
helper.isError()(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("with undefined 'key' and defined 'value' parameters", function () {
|
||||
it("reports an error", function () {
|
||||
client.mset(undefined, value, undefined, value2, function (err, res) {
|
||||
helper.isError()(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("and no callback is specified", function () {
|
||||
describe("with valid parameters", function () {
|
||||
it("sets the value correctly", function (done) {
|
||||
client.mset(key, value, key2, value2);
|
||||
|
||||
setTimeout(function () {
|
||||
async.parallel([function (next) {
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value)(err, res);
|
||||
next();
|
||||
});
|
||||
}, function (next) {
|
||||
client.get(key2, function (err, res) {
|
||||
helper.isString(value2)(err, res);
|
||||
next();
|
||||
});
|
||||
}], function (err) {
|
||||
done(err);
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with undefined 'key' and missing 'value' parameter", function () {
|
||||
// this behavior is different from the 'set' behavior.
|
||||
it("throws an error", function (done) {
|
||||
var mochaListener = removeMochaListener();
|
||||
|
||||
process.once('uncaughtException', function (err) {
|
||||
process.on('uncaughtException', mochaListener);
|
||||
helper.isError()(err, null);
|
||||
return done();
|
||||
});
|
||||
|
||||
client.mset();
|
||||
});
|
||||
});
|
||||
|
||||
describe("with undefined 'key' and defined 'value' parameters", function () {
|
||||
it("throws an error", function () {
|
||||
var mochaListener = removeMochaListener();
|
||||
|
||||
process.once('uncaughtException', function (err) {
|
||||
process.on('uncaughtException', mochaListener);
|
||||
helper.isError()(err, null);
|
||||
});
|
||||
|
||||
client.mset(undefined, value, undefined, value2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
['javascript', 'hiredis'].forEach(function (parser) {
|
||||
allTests(parser, "/tmp/redis.sock");
|
||||
['IPv4', 'IPv6'].forEach(function (ip) {
|
||||
allTests(parser, ip);
|
||||
})
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user