1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Increase the coverage by adding tests and fix a failing ready check

This commit is contained in:
Ruben Bridgewater
2015-09-21 02:38:27 +02:00
parent 6975b0723d
commit 6958c1854b
5 changed files with 79 additions and 44 deletions

View File

@@ -159,6 +159,34 @@ describe("client authentication", function () {
client.auth(auth, helper.isString('OK', done));
});
});
it('does not allow any commands to be processed if not authenticated using no_ready_check true', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
var args = config.configureClient(parser, ip, {
no_ready_check: true
});
client = redis.createClient.apply(redis.createClient, args);
client.on("ready", function () {
client.set('foo', 'bar', function (err, res) {
assert.equal(err.message, 'NOAUTH Authentication required.');
assert.equal(err.code, 'NOAUTH');
assert.equal(err.command, 'SET');
done();
});
});
});
it('does not allow auth to be provided post-hoc with auth method if not authenticated before', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
client = redis.createClient.apply(redis.createClient, args);
client.on("error", function (err) {
assert.equal(err.code, 'NOAUTH');
assert.equal(err.message, 'Ready check failed: NOAUTH Authentication required.');
assert.equal(err.command, 'INFO');
done();
});
});
});
});

View File

@@ -70,6 +70,7 @@ describe("The 'set' method", function () {
it("reports an error", function (done) {
client.set(undefined, function (err, res) {
helper.isError()(err, null);
assert.equal(err.command, 'SET');
done();
});
});
@@ -90,29 +91,36 @@ describe("The 'set' method", function () {
});
describe("with undefined 'key' and missing 'value' parameter", function () {
it("does not emit an error", function (done) {
this.timeout(200);
client.once("error", function (err) {
done(err);
});
client.set();
setTimeout(function () {
done();
}, 100);
});
it("does emit an error", function (done) {
it("emits an error without callback", function (done) {
client.on('error', function (err) {
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
assert.equal(err.message, 'send_command: SET value must not be undefined or null');
assert.equal(err.command, 'SET');
done();
});
client.set('foo');
client.set(undefined);
});
});
it("emit an error with only the key set", function (done) {
client.on('error', function (err) {
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
done();
});
client.set('foo');
});
it("emit an error without any parameters", function (done) {
client.once("error", function (err) {
assert.equal(err.message, 'send_command: SET value must not be undefined or null');
assert.equal(err.command, 'SET');
done();
});
// This was not supported not to throw earlier and was added by the test refactoring
// https://github.com/NodeRedis/node_redis/commit/eaca486ab1aecd1329f7452ad2f2255b1263606f
client.set();
});
});
});
});

View File

@@ -39,6 +39,16 @@ describe("The 'srem' method", function () {
});
});
it('allows multiple values to be removed with send_command', function (done) {
client.send_command('sadd', ['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
client.send_command('srem', ["set0", "member1", "member2"], helper.isNumber(2));
client.smembers("set0", function (err, res) {
assert.strictEqual(res.length, 1);
assert.ok(~res.indexOf("member0"));
return done(err);
});
});
it('handles a value missing from the set of values being removed', function (done) {
client.sadd(["set0", "member0", "member1", "member2"], helper.isNumber(3));
client.SREM(["set0", "member3", "member4"], helper.isNumber(0));

View File

@@ -829,17 +829,18 @@ describe("The node_redis client", function () {
var cb = function(err, reply) {
assert.equal(err.code, 'CONNECTION_BROKEN');
};
for (var i = 0; i < 10; i += 2) {
multi.set("foo" + i, "bar" + i);
for (var i = 0; i < 12; i += 3) {
client.set("foo" + i, "bar" + i);
multi.set("foo" + (i + 1), "bar" + (i + 1), cb);
multi.set("foo" + (i + 2), "bar" + (i + 2));
}
multi.exec();
assert.equal(client.command_queue.length, 13);
assert.equal(client.command_queue.length, 15);
helper.killConnection(client);
});
client.on("reconnecting", function (params) {
assert.equal(client.command_queue.length, 13);
assert.equal(client.command_queue.length, 15);
});
client.on('error', function(err) {