Skip to content

Commit afcd760

Browse files
author
Ruben Bridgewater
committed
Fix a test and add some more
1 parent fba0508 commit afcd760

File tree

4 files changed

+110
-9
lines changed

4 files changed

+110
-9
lines changed

test/commands/client.spec.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,25 @@ describe("The 'client' method", function () {
1111
var pattern = /addr=/;
1212

1313
describe("using " + parser + " and " + ip, function () {
14-
var client;
14+
var client, client2;
1515

1616
beforeEach(function (done) {
1717
client = redis.createClient.apply(redis.createClient, args);
18-
client.once("connect", function () {
18+
client.once("ready", function () {
1919
client.flushdb(done);
2020
});
2121
});
2222

23+
beforeEach(function (done) {
24+
client2 = redis.createClient.apply(redis.createClient, args);
25+
client2.once("ready", function () {
26+
done();
27+
});
28+
});
29+
2330
afterEach(function () {
2431
client.end();
32+
client2.end();
2533
});
2634

2735
describe('list', function () {
@@ -52,6 +60,25 @@ describe("The 'client' method", function () {
5260
});
5361
});
5462
});
63+
64+
describe('setname / getname', function () {
65+
66+
it('sets the name', function (done) {
67+
helper.serverVersionAtLeast.call(this, client, [2, 6, 9]);
68+
69+
client.client("setname", "RUTH", helper.isString('OK'));
70+
client2.client("setname", "RENEE", helper.isString('OK'));
71+
client2.client("setname", "MARTIN", helper.isString('OK'));
72+
client2.client("getname", function(err, res) {
73+
assert.equal(res, 'MARTIN');
74+
});
75+
client.client("getname", function(err, res) {
76+
assert.equal(res, 'RUTH');
77+
done();
78+
});
79+
});
80+
81+
});
5582
});
5683
});
5784
});

test/commands/zadd.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
var config = require("../lib/config");
4+
var helper = require("../helper");
5+
var assert = require('assert');
6+
var redis = config.redis;
7+
8+
describe("The 'zadd' method", function () {
9+
10+
helper.allTests(function(parser, ip, args) {
11+
12+
describe.only("using " + parser + " and " + ip, function () {
13+
var client;
14+
15+
beforeEach(function (done) {
16+
client = redis.createClient.apply(redis.createClient, args);
17+
client.once("connect", function () {
18+
client.flushdb(done);
19+
});
20+
});
21+
22+
it('reports an error', function (done) {
23+
client.zadd('infinity', [+'5t', "should not be possible"], helper.isError(done));
24+
});
25+
26+
it('return inf / -inf', function (done) {
27+
client.zadd('infinity', [+Infinity, "should be inf"], helper.isNumber(1));
28+
client.zadd('infinity', [-Infinity, "should be negative inf"], helper.isNumber(1));
29+
client.zadd('infinity', [99999999999999999999999, "should not be inf"], helper.isNumber(1));
30+
client.zrange('infinity', 0, -1, 'WITHSCORES', function (err, res) {
31+
assert.equal(res[5], 'inf');
32+
assert.equal(res[1], '-inf');
33+
assert.equal(res[3], '9.9999999999999992e+22');
34+
done();
35+
});
36+
});
37+
38+
afterEach(function () {
39+
client.end();
40+
});
41+
});
42+
});
43+
44+
});

test/commands/zscore.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
var config = require("../lib/config");
4+
var helper = require("../helper");
5+
var assert = require('assert');
6+
var redis = config.redis;
7+
8+
describe("The 'zscore' method", function () {
9+
10+
helper.allTests(function(parser, ip, args) {
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("connect", function () {
18+
client.flushdb(done);
19+
});
20+
});
21+
22+
it('should return the score of member in the sorted set at key', function (done) {
23+
client.zadd('myzset', 1, 'one');
24+
client.zscore('myzset', 'one', function (err, res) {
25+
assert.equal(res, 1);
26+
done();
27+
});
28+
});
29+
30+
afterEach(function () {
31+
client.end();
32+
});
33+
});
34+
});
35+
});

test/node_redis.spec.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,13 @@ describe("The node_redis client", function () {
151151
});
152152
});
153153

154-
it.skip("misusing the function should eventually throw (no command)", function (done) {
155-
var mochaListener = helper.removeMochaListener();
156-
157-
process.once('uncaughtException', function (err) {
158-
process.on('uncaughtException', mochaListener);
154+
it("misusing the function should eventually throw (no command)", function (done) {
155+
client.send_command(true, 'info', function (err, res) {
159156
assert(/ERR Protocol error/.test(err.message));
160157
assert.equal(err.command, true);
161158
assert.equal(err.code, 'ERR');
162159
done();
163160
});
164-
165-
client.send_command(true, 'info');
166161
});
167162

168163
it("misusing the function should eventually throw (wrong args)", function (done) {

0 commit comments

Comments
 (0)