You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Merge pull request #819 from NodeRedis/815-tweaks
minor tweaks to how we spawn tests in #815
This commit is contained in:
@@ -37,6 +37,14 @@ describe("The 'hmget' method", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('allows keys to be specified by passing an array as first argument', function (done) {
|
||||
client.HMGET([hash, "0123456789", "some manner of key"], function (err, reply) {
|
||||
assert.strictEqual("abcdefghij", reply[0].toString());
|
||||
assert.strictEqual("a type of value", reply[1].toString());
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('allows a single key to be specified in an array', function (done) {
|
||||
client.HMGET(hash, ["0123456789"], function (err, reply) {
|
||||
assert.strictEqual("abcdefghij", reply[0].toString());
|
||||
|
@@ -20,7 +20,7 @@ describe("The 'hmset' method", function () {
|
||||
});
|
||||
|
||||
it('handles redis-style syntax', function (done) {
|
||||
client.HMSET(hash, "0123456789", "abcdefghij", "some manner of key", "a type of value", helper.isString('OK'));
|
||||
client.HMSET(hash, "0123456789", "abcdefghij", "some manner of key", "a type of value", "otherTypes", 555, helper.isString('OK'));
|
||||
client.HGETALL(hash, function (err, obj) {
|
||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||
assert.equal(obj['some manner of key'], 'a type of value');
|
||||
@@ -29,7 +29,7 @@ describe("The 'hmset' method", function () {
|
||||
});
|
||||
|
||||
it('handles object-style syntax', function (done) {
|
||||
client.HMSET(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value"}, helper.isString('OK'));
|
||||
client.HMSET(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}, helper.isString('OK'));
|
||||
client.HGETALL(hash, function (err, obj) {
|
||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||
assert.equal(obj['some manner of key'], 'a type of value');
|
||||
@@ -37,6 +37,15 @@ describe("The 'hmset' method", function () {
|
||||
})
|
||||
});
|
||||
|
||||
it('handles object-style syntax and the key being a number', function (done) {
|
||||
client.HMSET(231232, {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}, helper.isString('OK'));
|
||||
client.HGETALL(231232, function (err, obj) {
|
||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||
assert.equal(obj['some manner of key'], 'a type of value');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('allows a numeric key', function (done) {
|
||||
client.HMSET(hash, 99, 'banana', helper.isString('OK'));
|
||||
client.HGETALL(hash, function (err, obj) {
|
||||
|
@@ -7,12 +7,6 @@ var uuid = require('uuid');
|
||||
|
||||
describe("The 'mset' method", function () {
|
||||
|
||||
function removeMochaListener () {
|
||||
var mochaListener = process.listeners('uncaughtException').pop();
|
||||
process.removeListener('uncaughtException', mochaListener);
|
||||
return mochaListener;
|
||||
}
|
||||
|
||||
helper.allTests(function(parser, ip, args) {
|
||||
|
||||
describe("using " + parser + " and " + ip, function () {
|
||||
@@ -102,7 +96,7 @@ describe("The 'mset' method", function () {
|
||||
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();
|
||||
var mochaListener = helper.removeMochaListener();
|
||||
|
||||
process.once('uncaughtException', function (err) {
|
||||
process.on('uncaughtException', mochaListener);
|
||||
@@ -116,7 +110,7 @@ describe("The 'mset' method", function () {
|
||||
|
||||
describe("with undefined 'key' and defined 'value' parameters", function () {
|
||||
it("throws an error", function () {
|
||||
var mochaListener = removeMochaListener();
|
||||
var mochaListener = helper.removeMochaListener();
|
||||
|
||||
process.once('uncaughtException', function (err) {
|
||||
process.on('uncaughtException', mochaListener);
|
||||
|
@@ -6,12 +6,6 @@ var redis = config.redis;
|
||||
|
||||
describe("The 'select' method", function () {
|
||||
|
||||
function removeMochaListener () {
|
||||
var mochaListener = process.listeners('uncaughtException').pop();
|
||||
process.removeListener('uncaughtException', mochaListener);
|
||||
return mochaListener;
|
||||
}
|
||||
|
||||
helper.allTests(function(parser, ip, args) {
|
||||
|
||||
describe("using " + parser + " and " + ip, function () {
|
||||
@@ -96,7 +90,7 @@ describe("The 'select' method", function () {
|
||||
|
||||
describe("with an invalid db index", function () {
|
||||
it("throws an error when callback not provided", function (done) {
|
||||
var mochaListener = removeMochaListener();
|
||||
var mochaListener = helper.removeMochaListener();
|
||||
assert.strictEqual(client.selected_db, null, "default db should be null");
|
||||
|
||||
process.once('uncaughtException', function (err) {
|
||||
|
@@ -7,12 +7,6 @@ var uuid = require('uuid');
|
||||
|
||||
describe("The 'set' method", function () {
|
||||
|
||||
function removeMochaListener () {
|
||||
var mochaListener = process.listeners('uncaughtException').pop();
|
||||
process.removeListener('uncaughtException', mochaListener);
|
||||
return mochaListener;
|
||||
}
|
||||
|
||||
helper.allTests(function(parser, ip, args) {
|
||||
|
||||
describe("using " + parser + " and " + ip, function () {
|
||||
@@ -123,7 +117,7 @@ describe("The 'set' method", function () {
|
||||
|
||||
it("does not throw an error", function (done) {
|
||||
this.timeout(200);
|
||||
var mochaListener = removeMochaListener();
|
||||
var mochaListener = helper.removeMochaListener();
|
||||
|
||||
process.once('uncaughtException', function (err) {
|
||||
process.on('uncaughtException', mochaListener);
|
||||
@@ -140,7 +134,7 @@ describe("The 'set' method", function () {
|
||||
|
||||
describe("with undefined 'key' and defined 'value' parameters", function () {
|
||||
it("throws an error", function () {
|
||||
var mochaListener = removeMochaListener();
|
||||
var mochaListener = helper.removeMochaListener();
|
||||
|
||||
process.once('uncaughtException', function (err) {
|
||||
process.on('uncaughtException', mochaListener);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
requirepass porkchopsandwiches
|
||||
port 6378
|
||||
port 6379
|
||||
bind ::1 127.0.0.1
|
||||
unixsocket /tmp/redis.sock
|
||||
unixsocketperm 755
|
||||
|
@@ -1,4 +1,4 @@
|
||||
port 6378
|
||||
port 6379
|
||||
bind ::1 127.0.0.1
|
||||
unixsocket /tmp/redis.sock
|
||||
unixsocketperm 755
|
||||
|
@@ -92,12 +92,21 @@ module.exports = {
|
||||
return true;
|
||||
},
|
||||
allTests: function (cb) {
|
||||
['javascript', 'hiredis'].forEach(function (parser) {
|
||||
cb(parser, "/tmp/redis.sock", config.configureClient(parser, "/tmp/redis.sock"));
|
||||
['IPv4', 'IPv6'].forEach(function (ip) {
|
||||
cb(parser, ip, config.configureClient(parser, ip));
|
||||
[undefined].forEach(function (options) { // add buffer option at some point
|
||||
describe(options && options.return_buffers ? "returning buffers" : "returning strings", function () {
|
||||
['hiredis', 'javascript'].forEach(function (parser) {
|
||||
cb(parser, "/tmp/redis.sock", config.configureClient(parser, "/tmp/redis.sock", options));
|
||||
['IPv4', 'IPv6'].forEach(function (ip) {
|
||||
cb(parser, ip, config.configureClient(parser, ip, options));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
removeMochaListener: function () {
|
||||
var mochaListener = process.listeners('uncaughtException').pop();
|
||||
process.removeListener('uncaughtException', mochaListener);
|
||||
return mochaListener;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ var redis = require('../../index');
|
||||
|
||||
var config = {
|
||||
redis: redis,
|
||||
PORT: 6378,
|
||||
PORT: 6379,
|
||||
HOST: {
|
||||
IPv4: "127.0.0.1",
|
||||
IPv6: "::1"
|
||||
|
@@ -11,6 +11,17 @@ module.exports = {
|
||||
var confFile = conf || path.resolve(__dirname, '../conf/redis.conf');
|
||||
var rp = cp.spawn("redis-server", [confFile], {});
|
||||
|
||||
// capture a failure booting redis, and give
|
||||
// the user running the test some directions.
|
||||
rp.once("exit", function (code) {
|
||||
if (code !== 0) {
|
||||
console.error('failed to starting redis with exit code "' + code + '" ' +
|
||||
'stop any other redis processes currently running (' +
|
||||
'hint: lsof -i :6379)');
|
||||
process.exit(code)
|
||||
}
|
||||
})
|
||||
|
||||
// wait for redis to become available, by
|
||||
// checking the port we bind on.
|
||||
waitForRedis(true, function () {
|
||||
|
@@ -9,15 +9,36 @@ describe("The node_redis client", function () {
|
||||
|
||||
helper.allTests(function(parser, ip, args) {
|
||||
|
||||
if (args[2]) { // skip if options are undefined
|
||||
describe("testing parser existence", function () {
|
||||
it('throws on non-existence', function (done) {
|
||||
var mochaListener = helper.removeMochaListener();
|
||||
|
||||
process.once('uncaughtException', function (err) {
|
||||
process.on('uncaughtException', mochaListener);
|
||||
assert.equal(err.message, 'Couldn\'t find named parser nonExistingParser on this system');
|
||||
return done();
|
||||
});
|
||||
|
||||
// Don't pollute the args for the other connections
|
||||
var tmp = JSON.parse(JSON.stringify(args));
|
||||
tmp[2].parser = 'nonExistingParser';
|
||||
redis.createClient.apply(redis.createClient, tmp);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe("using " + parser + " and " + ip, function () {
|
||||
var client;
|
||||
|
||||
describe("when not connected", function () {
|
||||
afterEach(function () {
|
||||
client.end();
|
||||
if (client) {
|
||||
client.end();
|
||||
}
|
||||
});
|
||||
|
||||
it("connects correctly", function (done) {
|
||||
it("connects correctly with args", function (done) {
|
||||
client = redis.createClient.apply(redis.createClient, args);
|
||||
client.on("error", done);
|
||||
|
||||
@@ -28,6 +49,58 @@ describe("The node_redis client", function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("connects correctly with default values", function (done) {
|
||||
client = redis.createClient();
|
||||
client.on("error", done);
|
||||
|
||||
client.once("ready", function () {
|
||||
client.removeListener("error", done);
|
||||
client.get("recon 1", function (err, res) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("connects correctly to localhost", function (done) {
|
||||
client = redis.createClient(null, null);
|
||||
client.on("error", done);
|
||||
|
||||
client.once("ready", function () {
|
||||
client.removeListener("error", done);
|
||||
client.get("recon 1", function (err, res) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("throws on strange connection info", function () {
|
||||
try {
|
||||
redis.createClient(true);
|
||||
throw new Error('failed');
|
||||
} catch (err) {
|
||||
assert.equal(err.message, 'unknown type of connection in createClient()');
|
||||
}
|
||||
});
|
||||
|
||||
if (ip === 'IPv4') {
|
||||
it('allows connecting with the redis url and the default port', function (done) {
|
||||
client = redis.createClient('redis://foo:porkchopsandwiches@' + config.HOST[ip]);
|
||||
client.on("ready", function () {
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('allows connecting with the redis url and no auth', function (done) {
|
||||
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, {
|
||||
detect_buffers: false
|
||||
});
|
||||
client.on("ready", function () {
|
||||
return done();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
describe("when connected", function () {
|
||||
|
Reference in New Issue
Block a user