-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #793 from NodeRedis/squash-mocha-work
porting tests from hand-rolled artisinal test-suite to mocha
- Loading branch information
Showing
65 changed files
with
4,869 additions
and
2,467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
var assert = require("assert"); | ||
var config = require("./lib/config"); | ||
var helper = require('./helper') | ||
var path = require('path'); | ||
var redis = config.redis; | ||
|
||
describe("client authentication", function () { | ||
before(function (done) { | ||
helper.stopRedis(function () { | ||
helper.startRedis('./conf/password.conf', done); | ||
}); | ||
}); | ||
|
||
function allTests(parser, ip) { | ||
describe("using " + parser + " and " + ip, function () { | ||
var args = config.configureClient(parser, ip); | ||
var auth = 'porkchopsandwiches'; | ||
var client = null; | ||
|
||
afterEach(function () { | ||
client.end(); | ||
}); | ||
|
||
it("allows auth to be provided with 'auth' method", function (done) { | ||
client = redis.createClient.apply(redis.createClient, args); | ||
client.auth(auth, function (err, res) { | ||
assert.strictEqual(null, err); | ||
assert.strictEqual("OK", res.toString()); | ||
return done(err); | ||
}); | ||
}); | ||
|
||
it("raises error when auth is bad", function (done) { | ||
client = redis.createClient.apply(redis.createClient, args); | ||
|
||
client.once('error', function (error) { | ||
assert.ok(/ERR invalid password/.test(error)) | ||
return done(); | ||
}); | ||
|
||
client.auth(auth + 'bad'); | ||
}); | ||
|
||
if (ip === 'IPv4') { | ||
it('allows auth to be provided as config option for client', function (done) { | ||
client = redis.createClient('redis://foo:' + auth + '@' + config.HOST[ip] + ':' + config.PORT); | ||
client.on("ready", function () { | ||
return done(); | ||
}); | ||
}); | ||
} | ||
|
||
it('allows auth to be provided as part of redis url', function (done) { | ||
var args = config.configureClient(parser, ip, { | ||
auth_pass: auth | ||
}); | ||
client = redis.createClient.apply(redis.createClient, args); | ||
client.on("ready", function () { | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('reconnects with appropriate authentication', function (done) { | ||
var readyCount = 0; | ||
client = redis.createClient.apply(redis.createClient, args); | ||
client.auth(auth); | ||
client.on("ready", function () { | ||
readyCount++; | ||
if (readyCount === 1) { | ||
client.stream.destroy(); | ||
} else { | ||
return done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
['javascript', 'hiredis'].forEach(function (parser) { | ||
allTests(parser, "/tmp/redis.sock"); | ||
['IPv4', 'IPv6'].forEach(function (ip) { | ||
allTests(parser, ip); | ||
}) | ||
}); | ||
|
||
after(function (done) { | ||
helper.stopRedis(function () { | ||
helper.startRedis('./conf/redis.conf', done); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
var assert = require("assert"); | ||
var config = require("../lib/config"); | ||
var helper = require("../helper"); | ||
var redis = config.redis; | ||
|
||
describe("The 'blpop' method", function () { | ||
|
||
function allTests(parser, ip) { | ||
var args = config.configureClient(parser, ip); | ||
|
||
describe("using " + parser + " and " + ip, function () { | ||
var client; | ||
var bclient; | ||
|
||
beforeEach(function (done) { | ||
client = redis.createClient.apply(redis.createClient, args); | ||
client.once("error", done); | ||
client.once("connect", function () { | ||
client.flushdb(done); | ||
}); | ||
}); | ||
|
||
it('pops value immediately if list contains values', function (done) { | ||
bclient = redis.createClient.apply(redis.createClient, args); | ||
client.rpush("blocking list", "initial value", helper.isNumber(1)); | ||
bclient.blpop("blocking list", 0, function (err, value) { | ||
assert.strictEqual(value[0], "blocking list"); | ||
assert.strictEqual(value[1], "initial value"); | ||
return done(err); | ||
}); | ||
}); | ||
|
||
it('waits for value if list is not yet populated', function (done) { | ||
bclient = redis.createClient.apply(redis.createClient, args); | ||
bclient.blpop("blocking list 2", 5, function (err, value) { | ||
assert.strictEqual(value[0], "blocking list 2"); | ||
assert.strictEqual(value[1], "initial value"); | ||
return done(err); | ||
}); | ||
client.rpush("blocking list 2", "initial value", helper.isNumber(1)); | ||
}); | ||
|
||
it('times out after specified time', function (done) { | ||
bclient = redis.createClient.apply(redis.createClient, args); | ||
bclient.BLPOP("blocking list", 1, function (err, res) { | ||
assert.strictEqual(res, null); | ||
return done(err); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
client.end(); | ||
bclient.end(); | ||
}); | ||
}); | ||
} | ||
|
||
['javascript', 'hiredis'].forEach(function (parser) { | ||
allTests(parser, "/tmp/redis.sock"); | ||
['IPv4', 'IPv6'].forEach(function (ip) { | ||
allTests(parser, ip); | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var assert = require("assert"); | ||
var config = require("../lib/config"); | ||
var helper = require("../helper"); | ||
var redis = config.redis; | ||
|
||
describe("The 'client' method", function () { | ||
|
||
function allTests(parser, ip) { | ||
var args = config.configureClient(parser, ip); | ||
var pattern = /addr=/; | ||
|
||
describe("using " + parser + " and " + ip, function () { | ||
var client; | ||
|
||
beforeEach(function (done) { | ||
client = redis.createClient.apply(redis.createClient, args); | ||
client.once("error", done); | ||
client.once("connect", function () { | ||
client.flushdb(function (err) { | ||
if (!helper.serverVersionAtLeast(client, [2, 4, 0])) { | ||
err = Error('script not supported in redis <= 2.4.0') | ||
} | ||
return done(err); | ||
|
||
}) | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
client.end(); | ||
}); | ||
|
||
describe('list', function () { | ||
it('lists connected clients', function (done) { | ||
client.client("list", helper.match(pattern, done)); | ||
}); | ||
|
||
it("lists connected clients when invoked with multi's chaining syntax", function (done) { | ||
client.multi().client("list").exec(function(err, results) { | ||
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString()); | ||
return done() | ||
}) | ||
}); | ||
|
||
it("lists connected clients when invoked with multi's array syntax", function (done) { | ||
client.multi().client("list").exec(function(err, results) { | ||
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString()); | ||
return done() | ||
}) | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
['javascript', 'hiredis'].forEach(function (parser) { | ||
allTests(parser, "/tmp/redis.sock"); | ||
['IPv4', 'IPv6'].forEach(function (ip) { | ||
allTests(parser, ip); | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
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 'dbsize' method", function () { | ||
|
||
function allTests(parser, ip) { | ||
var args = config.configureClient(parser, ip); | ||
|
||
describe("using " + parser + " and " + ip, function () { | ||
var key, value; | ||
|
||
beforeEach(function () { | ||
key = uuid.v4(); | ||
value = 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.dbsize([], 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 () { | ||
client.flushdb(function (err, res) { | ||
helper.isString("OK")(err, res); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
client.end(); | ||
}); | ||
|
||
it("returns a zero db size", function (done) { | ||
client.dbsize([], function (err, res) { | ||
helper.isNotError()(err, res); | ||
helper.isType.number()(err, res); | ||
assert.strictEqual(res, 0, "Initial db size should be 0"); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe("when more data is added to Redis", function () { | ||
var oldSize; | ||
|
||
beforeEach(function (done) { | ||
client.dbsize([], function (err, res) { | ||
helper.isType.number()(err, res); | ||
assert.strictEqual(res, 0, "Initial db size should be 0"); | ||
|
||
oldSize = res; | ||
|
||
client.set(key, value, function (err, res) { | ||
helper.isNotError()(err, res); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it("returns a larger db size", function (done) { | ||
client.dbsize([], function (err, res) { | ||
helper.isNotError()(err, res); | ||
helper.isType.positiveNumber()(err, res); | ||
assert.strictEqual(true, (oldSize < res), "Adding data should increase db size."); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
['javascript', 'hiredis'].forEach(function (parser) { | ||
allTests(parser, "/tmp/redis.sock"); | ||
['IPv4', 'IPv6'].forEach(function (ip) { | ||
allTests(parser, ip); | ||
}) | ||
}); | ||
}); |
Oops, something went wrong.