/
client.spec.js
155 lines (133 loc) · 6.63 KB
/
client.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'client' method", function () {
helper.allTests(function (ip, args) {
var pattern = /addr=/;
describe('using ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once('ready', function () {
client.flushdb(done);
});
});
afterEach(function () {
client.end(true);
});
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', helper.isType.string()).exec(helper.match(pattern, done));
});
it('lists connected clients when invoked with array syntax on client', function (done) {
client.multi().client(['list']).exec(helper.match(pattern, done));
});
it("lists connected clients when invoked with multi's array syntax", function (done) {
client.multi([
['client', 'list']
]).exec(helper.match(pattern, done));
});
});
describe('reply', function () {
describe('as normal command', function () {
it('on', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
assert.strictEqual(client.reply, 'ON');
client.client('reply', 'on', helper.isString('OK'));
assert.strictEqual(client.reply, 'ON');
client.set('foo', 'bar', done);
});
it('off', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
assert.strictEqual(client.reply, 'ON');
client.client(Buffer.from('REPLY'), 'OFF', helper.isUndefined());
assert.strictEqual(client.reply, 'OFF');
client.set('foo', 'bar', helper.isUndefined(done));
});
it('skip', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
assert.strictEqual(client.reply, 'ON');
client.client('REPLY', Buffer.from('SKIP'), helper.isUndefined());
assert.strictEqual(client.reply, 'SKIP_ONE_MORE');
client.set('foo', 'bar', helper.isUndefined());
client.get('foo', helper.isString('bar', done));
});
});
describe('in a batch context', function () {
it('on', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
var batch = client.batch();
assert.strictEqual(client.reply, 'ON');
batch.client('reply', 'on', helper.isString('OK'));
assert.strictEqual(client.reply, 'ON');
batch.set('foo', 'bar');
batch.exec(function (err, res) {
assert.deepEqual(res, ['OK', 'OK']);
done(err);
});
});
it('off', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
var batch = client.batch();
assert.strictEqual(client.reply, 'ON');
batch.set('hello', 'world');
batch.client(Buffer.from('REPLY'), Buffer.from('OFF'), helper.isUndefined());
batch.set('foo', 'bar', helper.isUndefined());
batch.exec(function (err, res) {
assert.strictEqual(client.reply, 'OFF');
assert.deepEqual(res, ['OK', undefined, undefined]);
done(err);
});
});
it('skip', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
assert.strictEqual(client.reply, 'ON');
client.batch()
.set('hello', 'world')
.client('REPLY', 'SKIP', helper.isUndefined())
.set('foo', 'bar', helper.isUndefined())
.get('foo')
.exec(function (err, res) {
assert.strictEqual(client.reply, 'ON');
assert.deepEqual(res, ['OK', undefined, undefined, 'bar']);
done(err);
});
});
});
});
describe('setname / getname', function () {
var client2;
beforeEach(function (done) {
client2 = redis.createClient.apply(null, args);
client2.once('ready', function () {
done();
});
});
afterEach(function () {
client2.end(true);
});
it('sets the name', function (done) {
// The querys are auto pipelined and the response is a response to all querys of one client
// per chunk. So the execution order is only garanteed on each client
var end = helper.callFuncAfter(done, 2);
client.client('setname', 'RUTH');
client2.client('setname', ['RENEE'], helper.isString('OK'));
client2.client(['setname', 'MARTIN'], helper.isString('OK'));
client2.client('getname', function (err, res) {
assert.equal(res, 'MARTIN');
end();
});
client.client('getname', function (err, res) {
assert.equal(res, 'RUTH');
end();
});
});
});
});
});
});