Skip to content

Commit a0832c3

Browse files
author
Benjamin Coe
committed
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
1 parent 04fe11b commit a0832c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3013
-2593
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ sudo: true
33
node_js:
44
- "0.10"
55
- "0.12"
6-
- "iojs"
7-
script: npm run mocha
6+
- "iojs-v2"
87
after_success: npm run coverage

package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"main": "./index.js",
1212
"scripts": {
1313
"coverage": "nyc report --reporter=text-lcov | coveralls",
14-
"test": "nyc ./test/run.sh",
15-
"mocha": "nyc ./node_modules/.bin/_mocha ./test/mocha/*.js ./test/mocha/commands/*.js"
14+
"test": "nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000"
1615
},
1716
"devDependencies": {
1817
"async": "^1.3.0",
@@ -23,14 +22,11 @@
2322
"mocha": "^2.2.5",
2423
"nyc": "^3.0.0",
2524
"tcp-port-used": "^0.1.2",
26-
"underscore": "~1.4.4"
25+
"underscore": "~1.4.4",
26+
"uuid": "^2.0.1"
2727
},
2828
"repository": {
2929
"type": "git",
3030
"url": "git://github.com/mranney/node_redis.git"
31-
},
32-
"dependencies": {
33-
"sinon": "^1.15.4",
34-
"uuid": "^2.0.1"
3531
}
3632
}

test/auth.spec.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
var assert = require("assert");
2+
var config = require("./lib/config");
3+
var helper = require('./helper')
4+
var path = require('path');
5+
var redis = config.redis;
6+
7+
describe("client authentication", function () {
8+
before(function (done) {
9+
helper.stopRedis(function () {
10+
helper.startRedis('./conf/password.conf', done);
11+
});
12+
});
13+
14+
function allTests(parser, ip) {
15+
describe("using " + parser + " and " + ip, function () {
16+
var args = config.configureClient(parser, ip);
17+
var auth = 'porkchopsandwiches';
18+
var client = null;
19+
20+
afterEach(function () {
21+
client.end();
22+
});
23+
24+
it("allows auth to be provided with 'auth' method", function (done) {
25+
client = redis.createClient.apply(redis.createClient, args);
26+
client.auth(auth, function (err, res) {
27+
assert.strictEqual(null, err);
28+
assert.strictEqual("OK", res.toString());
29+
return done(err);
30+
});
31+
});
32+
33+
it("raises error when auth is bad", function (done) {
34+
client = redis.createClient.apply(redis.createClient, args);
35+
36+
client.once('error', function (error) {
37+
assert.ok(/ERR invalid password/.test(error))
38+
return done();
39+
});
40+
41+
client.auth(auth + 'bad');
42+
});
43+
44+
if (ip === 'IPv4')
45+
it('allows auth to be provided as config option for client', function (done) {
46+
client = redis.createClient('redis://foo:' + auth + '@' + config.HOST[ip] + ':' + config.PORT);
47+
client.on("ready", function () {
48+
return done();
49+
});
50+
});
51+
52+
it('allows auth to be provided as part of redis url', function (done) {
53+
var args = config.configureClient(parser, ip, {
54+
auth_pass: auth
55+
});
56+
client = redis.createClient.apply(redis.createClient, args);
57+
client.on("ready", function () {
58+
return done();
59+
});
60+
});
61+
62+
it('reconnects with appropriate authentication', function (done) {
63+
var readyCount = 0;
64+
client = redis.createClient.apply(redis.createClient, args);
65+
client.auth(auth);
66+
client.on("ready", function () {
67+
readyCount++;
68+
if (readyCount === 1) {
69+
client.stream.destroy();
70+
} else {
71+
return done();
72+
}
73+
});
74+
});
75+
});
76+
}
77+
78+
['javascript', 'hiredis'].forEach(function (parser) {
79+
allTests(parser, "/tmp/redis.sock");
80+
['IPv4', 'IPv6'].forEach(function (ip) {
81+
allTests(parser, ip);
82+
})
83+
});
84+
85+
after(function (done) {
86+
helper.stopRedis(function () {
87+
helper.startRedis('./conf/redis.conf', done);
88+
});
89+
});
90+
});

test/commands/client.spec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var assert = require("assert");
2+
var config = require("../lib/config");
3+
var helper = require("../helper");
4+
var redis = config.redis;
5+
6+
describe("The 'client' method", function () {
7+
8+
function allTests(parser, ip) {
9+
var args = config.configureClient(parser, ip);
10+
var pattern = /addr=/;
11+
12+
describe("using " + parser + " and " + ip, function () {
13+
var client;
14+
15+
beforeEach(function (done) {
16+
client = redis.createClient.apply(redis.createClient, args);
17+
client.once("error", done);
18+
client.once("connect", function () {
19+
client.flushdb(function (err) {
20+
if (!helper.serverVersionAtLeast(client, [2, 4, 0])) {
21+
err = Error('script not supported in redis <= 2.4.0')
22+
}
23+
return done(err);
24+
25+
})
26+
});
27+
});
28+
29+
afterEach(function () {
30+
client.end();
31+
});
32+
33+
describe('list', function () {
34+
it('lists connected clients', function (done) {
35+
client.client("list", helper.match(pattern, done));
36+
});
37+
38+
it("lists connected clients when invoked with multi's chaining syntax", function (done) {
39+
client.multi().client("list").exec(function(err, results) {
40+
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString());
41+
return done()
42+
})
43+
});
44+
45+
it("lists connected clients when invoked with multi's array syntax", function (done) {
46+
client.multi().client("list").exec(function(err, results) {
47+
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString());
48+
return done()
49+
})
50+
});
51+
});
52+
});
53+
}
54+
55+
['javascript', 'hiredis'].forEach(function (parser) {
56+
allTests(parser, "/tmp/redis.sock");
57+
['IPv4', 'IPv6'].forEach(function (ip) {
58+
allTests(parser, ip);
59+
})
60+
});
61+
});

test/mocha/commands/dbsize.spec.js renamed to test/commands/dbsize.spec.js

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
var async = require('async');
22
var assert = require('assert');
3-
var config = require("../../lib/config");
4-
var nodeAssert = require('../../lib/nodeify-assertions');
3+
var config = require("../lib/config");
4+
var helper = require('../helper');
55
var redis = config.redis;
6-
var RedisProcess = require("../../lib/redis-process");
76
var uuid = require('uuid');
87

98
describe("The 'dbsize' method", function () {
109

11-
var rp;
12-
before(function (done) {
13-
RedisProcess.start(function (err, _rp) {
14-
rp = _rp;
15-
return done(err);
16-
});
17-
})
18-
19-
function removeMochaListener () {
20-
var mochaListener = process.listeners('uncaughtException').pop();
21-
process.removeListener('uncaughtException', mochaListener);
22-
return mochaListener;
23-
}
24-
2510
function allTests(parser, ip) {
2611
var args = config.configureClient(parser, ip);
2712

@@ -63,7 +48,7 @@ describe("The 'dbsize' method", function () {
6348
client.once("error", done);
6449
client.once("connect", function () {
6550
client.flushdb(function (err, res) {
66-
nodeAssert.isString("OK")(err, res);
51+
helper.isString("OK")(err, res);
6752
done();
6853
});
6954
});
@@ -75,8 +60,8 @@ describe("The 'dbsize' method", function () {
7560

7661
it("returns a zero db size", function (done) {
7762
client.dbsize([], function (err, res) {
78-
nodeAssert.isNotError()(err, res);
79-
nodeAssert.isType.number()(err, res);
63+
helper.isNotError()(err, res);
64+
helper.isType.number()(err, res);
8065
assert.strictEqual(res, 0, "Initial db size should be 0");
8166
done();
8267
});
@@ -87,22 +72,22 @@ describe("The 'dbsize' method", function () {
8772

8873
beforeEach(function (done) {
8974
client.dbsize([], function (err, res) {
90-
nodeAssert.isType.number()(err, res);
75+
helper.isType.number()(err, res);
9176
assert.strictEqual(res, 0, "Initial db size should be 0");
9277

9378
oldSize = res;
9479

9580
client.set(key, value, function (err, res) {
96-
nodeAssert.isNotError()(err, res);
81+
helper.isNotError()(err, res);
9782
done();
9883
});
9984
});
10085
});
10186

10287
it("returns a larger db size", function (done) {
10388
client.dbsize([], function (err, res) {
104-
nodeAssert.isNotError()(err, res);
105-
nodeAssert.isType.positiveNumber()(err, res);
89+
helper.isNotError()(err, res);
90+
helper.isType.positiveNumber()(err, res);
10691
assert.strictEqual(true, (oldSize < res), "Adding data should increase db size.");
10792
done();
10893
});
@@ -118,8 +103,4 @@ describe("The 'dbsize' method", function () {
118103
allTests(parser, ip);
119104
})
120105
});
121-
122-
after(function (done) {
123-
if (rp) rp.stop(done);
124-
});
125106
});

test/commands/del.spec.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var assert = require("assert");
2+
var config = require("../lib/config");
3+
var helper = require("../helper");
4+
var redis = config.redis;
5+
6+
describe("The 'del' method", function () {
7+
8+
function allTests(parser, ip) {
9+
var args = config.configureClient(parser, ip);
10+
11+
describe("using " + parser + " and " + ip, function () {
12+
var client;
13+
14+
beforeEach(function (done) {
15+
client = redis.createClient.apply(redis.createClient, args);
16+
client.once("error", done);
17+
client.once("connect", function () {
18+
client.flushdb(done);
19+
});
20+
});
21+
22+
it('allows a single key to be deleted', function (done) {
23+
client.set('foo', 'bar');
24+
client.del('foo', helper.isNumber(1));
25+
client.get('foo', helper.isNull(done));
26+
});
27+
28+
it('allows del to be called on a key that does not exist', function (done) {
29+
client.del('foo', helper.isNumber(0, done));
30+
});
31+
32+
it('allows multiple keys to be deleted', function (done) {
33+
client.mset('foo', 'bar', 'apple', 'banana');
34+
client.del('foo', 'apple', helper.isNumber(2));
35+
client.get('foo', helper.isNull());
36+
client.get('apple', helper.isNull(done));
37+
});
38+
39+
afterEach(function () {
40+
client.end();
41+
});
42+
});
43+
}
44+
45+
['javascript', 'hiredis'].forEach(function (parser) {
46+
allTests(parser, "/tmp/redis.sock");
47+
['IPv4', 'IPv6'].forEach(function (ip) {
48+
allTests(parser, ip);
49+
})
50+
});
51+
});

0 commit comments

Comments
 (0)