Skip to content

Commit bf2ccd9

Browse files
committed
Merge pull request #837 from NodeRedis/windows-tests
retrofit tests so that they work on Windows
2 parents 06121a6 + bb221ad commit bf2ccd9

22 files changed

+200
-135
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ redis - a node.js redis client
33

44
[![Build Status](https://travis-ci.org/NodeRedis/node_redis.png)](https://travis-ci.org/NodeRedis/node_redis)
55
[![Coverage Status](https://coveralls.io/repos/NodeRedis/node_redis/badge.svg?branch=)](https://coveralls.io/r/NodeRedis/node_redis?branch=)
6+
[![Windows Tests](https://img.shields.io/appveyor/ci/bcoe/node-redis/master.svg?label=Windows%20Tests)](https://ci.appveyor.com/project/bcoe/node-redis)
67

78
This is a complete Redis client for node.js. It supports all Redis commands,
89
including many recently added commands.

appveyor.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# http://www.appveyor.com/docs/appveyor-yml
2+
3+
# Test against these versions of Node.js.
4+
environment:
5+
matrix:
6+
- nodejs_version: "0.10"
7+
- nodejs_version: "0.12"
8+
- nodejs_version: "3.0"
9+
- nodejs_version: "4.0"
10+
11+
# Install scripts. (runs after repo cloning)
12+
install:
13+
# Install the Redis
14+
- nuget install redis-64 -excludeversion
15+
- redis-64\redis-server.exe --service-install
16+
- redis-64\redis-server.exe --service-start
17+
- '@ECHO Redis Started'
18+
# Get the latest stable version of Node 0.STABLE.latest
19+
- ps: Install-Product node $env:nodejs_version
20+
# Typical npm stuff.
21+
- npm install
22+
23+
# Post-install test scripts.
24+
test_script:
25+
# Output useful info for debugging.
26+
- node --version
27+
- npm --version
28+
- cmd: npm t
29+
30+
os:
31+
- Default Azure
32+
- Windows Server 2012 R2
33+
34+
# Don't actually build using MSBuild
35+
build: off
36+
37+
# Set build version format here instead of in the admin panel.
38+
version: "{build}"

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212
"scripts": {
1313
"coveralls": "nyc report --reporter=text-lcov | coveralls",
1414
"coverage": "nyc report --reporter=html",
15-
"test": "./node_modules/.bin/jshint * && nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000",
16-
"jshint": "./node_modules/.bin/jshint *"
15+
"test": "nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000",
16+
"pretest": "optional-dev-dependency hiredis",
17+
"posttest": "jshint ."
1718
},
1819
"devDependencies": {
1920
"coveralls": "^2.11.2",
20-
"hiredis": "^0.4.1",
2121
"jshint": "^2.8.0",
2222
"metrics": ">=0.1.5",
2323
"mocha": "^2.2.5",
24-
"nyc": "^3.0.0",
24+
"nyc": "^3.2.2",
25+
"optional-dev-dependency": "^1.0.1",
2526
"tcp-port-used": "^0.1.2",
26-
"uuid": "^2.0.1"
27+
"uuid": "^2.0.1",
28+
"win-spawn": "^2.0.0"
2729
},
2830
"repository": {
2931
"type": "git",

test/auth.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ describe("client authentication", function () {
2424
});
2525

2626
it("allows auth to be provided with 'auth' method", function (done) {
27+
if (helper.redisProcess().spawnFailed()) this.skip();
28+
2729
client = redis.createClient.apply(redis.createClient, args);
2830
client.auth(auth, function (err, res) {
2931
assert.strictEqual(null, err);
@@ -33,6 +35,8 @@ describe("client authentication", function () {
3335
});
3436

3537
it("raises error when auth is bad", function (done) {
38+
if (helper.redisProcess().spawnFailed()) this.skip();
39+
3640
client = redis.createClient.apply(redis.createClient, args);
3741

3842
client.once('error', function (error) {
@@ -45,6 +49,8 @@ describe("client authentication", function () {
4549

4650
if (ip === 'IPv4') {
4751
it('allows auth to be provided as part of redis url', function (done) {
52+
if (helper.redisProcess().spawnFailed()) this.skip();
53+
4854
client = redis.createClient('redis://foo:' + auth + '@' + config.HOST[ip] + ':' + config.PORT);
4955
client.on("ready", function () {
5056
return done();
@@ -53,6 +59,8 @@ describe("client authentication", function () {
5359
}
5460

5561
it('allows auth to be provided as config option for client', function (done) {
62+
if (helper.redisProcess().spawnFailed()) this.skip();
63+
5664
var args = config.configureClient(parser, ip, {
5765
auth_pass: auth
5866
});
@@ -62,7 +70,20 @@ describe("client authentication", function () {
6270
});
6371
});
6472

73+
it('allows auth to be provided post-hoc with auth method', function (done) {
74+
if (helper.redisProcess().spawnFailed()) this.skip();
75+
76+
var args = config.configureClient(parser, ip);
77+
client = redis.createClient.apply(redis.createClient, args);
78+
client.auth(auth);
79+
client.on("ready", function () {
80+
return done();
81+
});
82+
});
83+
6584
it('reconnects with appropriate authentication', function (done) {
85+
if (helper.redisProcess().spawnFailed()) this.skip();
86+
6687
var readyCount = 0;
6788
client = redis.createClient.apply(redis.createClient, args);
6889
client.auth(auth);

test/commands/client.spec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ describe("The 'client' method", function () {
1717
client = redis.createClient.apply(redis.createClient, args);
1818
client.once("error", done);
1919
client.once("connect", function () {
20-
client.flushdb(function (err) {
21-
if (!helper.serverVersionAtLeast(client, [2, 4, 0])) {
22-
err = Error('script not supported in redis <= 2.4.0');
23-
}
24-
return done(err);
25-
});
20+
client.flushdb(done);
2621
});
2722
});
2823

test/commands/dbsize.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("The 'dbsize' method", function () {
3434

3535
it("reports an error", function (done) {
3636
client.dbsize([], function (err, res) {
37-
assert.equal(err.message, 'Redis connection gone from end event.');
37+
assert(err.message.match(/Redis connection gone/));
3838
done();
3939
});
4040
});

test/commands/eval.spec.js

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ describe("The 'eval' method", function () {
1717
client = redis.createClient.apply(redis.createClient, args);
1818
client.once("error", done);
1919
client.once("connect", function () {
20-
client.flushdb(function (err) {
21-
if (!helper.serverVersionAtLeast(client, [2, 5, 0])) {
22-
err = Error('exec not supported in redis <= 2.5.0');
23-
}
24-
return done(err);
25-
});
20+
client.flushdb(done);
2621
});
2722
});
2823

@@ -31,30 +26,37 @@ describe("The 'eval' method", function () {
3126
});
3227

3328
it('converts a float to an integer when evaluated', function (done) {
29+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
3430
client.eval("return 100.5", 0, helper.isNumber(100, done));
3531
});
3632

3733
it('returns a string', function (done) {
38-
client.EVAL("return 'hello world'", 0, helper.isString('hello world', done));
34+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
35+
client.eval("return 'hello world'", 0, helper.isString('hello world', done));
3936
});
4037

4138
it('converts boolean true to integer 1', function (done) {
39+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
4240
client.eval("return true", 0, helper.isNumber(1, done));
4341
});
4442

4543
it('converts boolean false to null', function (done) {
44+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
4645
client.eval("return false", 0, helper.isNull(done));
4746
});
4847

4948
it('converts lua status code to string representation', function (done) {
49+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
5050
client.eval("return {ok='fine'}", 0, helper.isString('fine', done));
5151
});
5252

5353
it('converts lua error to an error response', function (done) {
54+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
5455
client.eval("return {err='this is an error'}", 0, helper.isError(done));
5556
});
5657

5758
it('represents a lua table appropritely', function (done) {
59+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
5860
client.eval("return {1,2,3,'ciao',{1,2}}", 0, function (err, res) {
5961
assert.strictEqual(5, res.length);
6062
assert.strictEqual(1, res[0]);
@@ -69,25 +71,27 @@ describe("The 'eval' method", function () {
6971
});
7072

7173
it('populates keys and argv correctly', function (done) {
72-
client.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d", function (err, res) {
73-
assert.strictEqual(4, res.length);
74-
assert.strictEqual("a", res[0]);
75-
assert.strictEqual("b", res[1]);
76-
assert.strictEqual("c", res[2]);
77-
assert.strictEqual("d", res[3]);
78-
return done();
79-
});
74+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
75+
client.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d", function (err, res) {
76+
assert.strictEqual(4, res.length);
77+
assert.strictEqual("a", res[0]);
78+
assert.strictEqual("b", res[1]);
79+
assert.strictEqual("c", res[2]);
80+
assert.strictEqual("d", res[3]);
81+
return done();
82+
});
8083
});
8184

8285
it('allows arguments to be provided in array rather than as multiple parameters', function (done) {
83-
client.eval(["return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d"], function (err, res) {
84-
assert.strictEqual(4, res.length);
85-
assert.strictEqual("a", res[0]);
86-
assert.strictEqual("b", res[1]);
87-
assert.strictEqual("c", res[2]);
88-
assert.strictEqual("d", res[3]);
89-
return done();
90-
});
86+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
87+
client.eval(["return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d"], function (err, res) {
88+
assert.strictEqual(4, res.length);
89+
assert.strictEqual("a", res[0]);
90+
assert.strictEqual("b", res[1]);
91+
assert.strictEqual("c", res[2]);
92+
assert.strictEqual("d", res[3]);
93+
return done();
94+
});
9195
});
9296

9397
describe('evalsha', function () {
@@ -101,19 +105,23 @@ describe("The 'eval' method", function () {
101105
});
102106

103107
it('allows a script to be executed that accesses the redis API', function (done) {
108+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
104109
client.eval(source, 0, helper.isString('eval get sha test', done));
105110
});
106111

107112
it('can execute a script if the SHA exists', function (done) {
113+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
108114
client.evalsha(sha, 0, helper.isString('eval get sha test', done));
109115
});
110116

111117
it('throws an error if SHA does not exist', function (done) {
118+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
112119
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0, helper.isError(done));
113120
});
114121
});
115122

116123
it('allows a key to be incremented, and performs appropriate conversion from LUA type', function (done) {
124+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
117125
client.set("incr key", 0, function (err, reply) {
118126
if (err) return done(err);
119127
client.eval("local foo = redis.call('incr','incr key')\n" + "return {type(foo),foo}", 0, function (err, res) {
@@ -126,6 +134,7 @@ describe("The 'eval' method", function () {
126134
});
127135

128136
it('allows a bulk operation to be performed, and performs appropriate conversion from LUA type', function (done) {
137+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
129138
client.set("bulk reply key", "bulk reply value", function (err, res) {
130139
client.eval("local foo = redis.call('get','bulk reply key'); return {type(foo),foo}", 0, function (err, res) {
131140
assert.strictEqual(2, res.length);
@@ -137,6 +146,7 @@ describe("The 'eval' method", function () {
137146
});
138147

139148
it('allows a multi mulk operation to be performed, with the appropriate type conversion', function (done) {
149+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
140150
client.multi()
141151
.del("mylist")
142152
.rpush("mylist", "a")
@@ -157,6 +167,7 @@ describe("The 'eval' method", function () {
157167
});
158168

159169
it('returns an appropriate representation of Lua status reply', function (done) {
170+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
160171
client.eval("local foo = redis.call('set','mykey','myval'); return {type(foo),foo['ok']}", 0, function (err, res) {
161172
assert.strictEqual(2, res.length);
162173
assert.strictEqual("table", res[0]);
@@ -166,6 +177,7 @@ describe("The 'eval' method", function () {
166177
});
167178

168179
it('returns an appropriate representation of a Lua error reply', function (done) {
180+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
169181
client.set("error reply key", "error reply value", function (err, res) {
170182
if (err) return done(err);
171183
client.eval("local foo = redis.pcall('incr','error reply key'); return {type(foo),foo['err']}", 0, function (err, res) {
@@ -178,6 +190,7 @@ describe("The 'eval' method", function () {
178190
});
179191

180192
it('returns an appropriate representation of a Lua nil reply', function (done) {
193+
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
181194
client.del("nil reply key", function (err, res) {
182195
if (err) return done(err);
183196
client.eval("local foo = redis.call('get','nil reply key'); return {type(foo),foo == false}", 0, function (err, res) {

test/commands/expire.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe("The 'expire' method", function () {
2424
client.EXPIRE(["expiry key", "1"], helper.isNumber(1));
2525
setTimeout(function () {
2626
client.exists(["expiry key"], helper.isNumber(0, done));
27-
}, 1100);
27+
}, 3000);
2828
});
2929

3030
afterEach(function () {

test/commands/flushdb.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("The 'flushdb' method", function () {
3434

3535
it("reports an error", function (done) {
3636
client.flushdb(function (err, res) {
37-
assert.equal(err.message, 'Redis connection gone from end event.');
37+
assert(err.message.match(/Redis connection gone/));
3838
done();
3939
});
4040
});

test/commands/get.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("The 'get' method", function () {
3434

3535
it("reports an error", function (done) {
3636
client.get(key, function (err, res) {
37-
assert.equal(err.message, 'Redis connection gone from end event.');
37+
assert(err.message.match(/Redis connection gone/));
3838
done();
3939
});
4040
});

0 commit comments

Comments
 (0)