@@ -5,7 +5,6 @@ var assert = require('assert');
5
5
6
6
var redisCache ;
7
7
var customRedisCache ;
8
- var customRedisCache2 ;
9
8
10
9
before ( function ( ) {
11
10
redisCache = require ( 'cache-manager' ) . caching ( {
@@ -25,20 +24,11 @@ before(function () {
25
24
ttl : config . redis . ttl ,
26
25
isCacheableValue : function ( val ) {
27
26
// allow undefined
28
- if ( val === undefined ) return true ;
29
- return redisCache . store . isCacheableValue ( val ) ;
30
- }
31
- } ) ;
32
-
33
- customRedisCache2 = require ( 'cache-manager' ) . caching ( {
34
- store : redisStore ,
35
- host : config . redis . host ,
36
- port : config . redis . port ,
37
- db : config . redis . db ,
38
- ttl : config . redis . ttl ,
39
- isCacheableValue : function ( val ) {
27
+ if ( val === undefined )
28
+ return true ;
40
29
// disallow FooBarString
41
- if ( val === 'FooBarString' ) return false ;
30
+ else if ( val === 'FooBarString' )
31
+ return false ;
42
32
return redisCache . store . isCacheableValue ( val ) ;
43
33
}
44
34
} ) ;
@@ -92,20 +82,20 @@ describe('set', function () {
92
82
done ( ) ;
93
83
} ) ;
94
84
} ) ;
85
+ } ) ;
95
86
96
- it ( 'should store a null value without error' , function ( done ) {
97
- redisCache . set ( 'foo2' , null , function ( err ) {
98
- try {
87
+ it ( 'should store a null value without error' , function ( done ) {
88
+ redisCache . set ( 'foo2' , null , function ( err ) {
89
+ try {
90
+ assert . equal ( err , null ) ;
91
+ redisCache . get ( 'foo2' , function ( err , value ) {
99
92
assert . equal ( err , null ) ;
100
- redisCache . get ( 'foo2' , function ( err , value ) {
101
- assert . equal ( err , null ) ;
102
- assert . equal ( value , null ) ;
103
- done ( ) ;
104
- } ) ;
105
- } catch ( e ) {
106
- done ( e ) ;
107
- }
108
- } ) ;
93
+ assert . equal ( value , null ) ;
94
+ done ( ) ;
95
+ } ) ;
96
+ } catch ( e ) {
97
+ done ( e ) ;
98
+ }
109
99
} ) ;
110
100
} ) ;
111
101
@@ -130,7 +120,7 @@ describe('set', function () {
130
120
} ) ;
131
121
} ) ;
132
122
133
- it ( 'should store an undefined value if permitted by isCacheableValue' , function ( done ) {
123
+ it ( 'should store an undefined value if permitted by isCacheableValue' , function ( done ) {
134
124
assert ( customRedisCache . store . isCacheableValue ( undefined ) , true ) ;
135
125
customRedisCache . set ( 'foo3' , undefined , function ( err ) {
136
126
try {
@@ -152,8 +142,8 @@ describe('set', function () {
152
142
} ) ;
153
143
154
144
it ( 'should not store a value disallowed by isCacheableValue' , function ( done ) {
155
- assert . strictEqual ( customRedisCache2 . store . isCacheableValue ( 'FooBarString' ) , false ) ;
156
- customRedisCache2 . set ( 'foobar' , 'FooBarString' , function ( err ) {
145
+ assert . strictEqual ( customRedisCache . store . isCacheableValue ( 'FooBarString' ) , false ) ;
146
+ customRedisCache . set ( 'foobar' , 'FooBarString' , function ( err ) {
157
147
try {
158
148
assert . notEqual ( err , null ) ;
159
149
assert . equal ( err . message , 'value cannot be FooBarString' ) ;
@@ -199,10 +189,10 @@ describe('get', function () {
199
189
200
190
it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
201
191
var pool = redisCache . store . _pool ;
202
- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
192
+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
203
193
sinon . stub ( pool , 'release' ) ;
204
194
redisCache . get ( 'foo' , function ( err ) {
205
- pool . acquire . restore ( ) ;
195
+ pool . acquireDb . restore ( ) ;
206
196
pool . release . restore ( ) ;
207
197
assert . notEqual ( err , null ) ;
208
198
done ( ) ;
@@ -229,11 +219,11 @@ describe('del', function () {
229
219
230
220
it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
231
221
var pool = redisCache . store . _pool ;
232
- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
222
+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
233
223
sinon . stub ( pool , 'release' ) ;
234
224
redisCache . set ( 'foo' , 'bar' , function ( ) {
235
225
redisCache . del ( 'foo' , function ( err ) {
236
- pool . acquire . restore ( ) ;
226
+ pool . acquireDb . restore ( ) ;
237
227
pool . release . restore ( ) ;
238
228
assert . notEqual ( err , null ) ;
239
229
done ( ) ;
@@ -257,10 +247,10 @@ describe('reset', function () {
257
247
258
248
it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
259
249
var pool = redisCache . store . _pool ;
260
- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
250
+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
261
251
sinon . stub ( pool , 'release' ) ;
262
252
redisCache . reset ( function ( err ) {
263
- pool . acquire . restore ( ) ;
253
+ pool . acquireDb . restore ( ) ;
264
254
pool . release . restore ( ) ;
265
255
assert . notEqual ( err , null ) ;
266
256
done ( ) ;
@@ -289,11 +279,11 @@ describe('ttl', function () {
289
279
290
280
it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
291
281
var pool = redisCache . store . _pool ;
292
- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
282
+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
293
283
sinon . stub ( pool , 'release' ) ;
294
284
redisCache . set ( 'foo' , 'bar' , function ( ) {
295
285
redisCache . ttl ( 'foo' , function ( err ) {
296
- pool . acquire . restore ( ) ;
286
+ pool . acquireDb . restore ( ) ;
297
287
pool . release . restore ( ) ;
298
288
assert . notEqual ( err , null ) ;
299
289
done ( ) ;
@@ -327,11 +317,11 @@ describe('keys', function () {
327
317
328
318
it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
329
319
var pool = redisCache . store . _pool ;
330
- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
320
+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
331
321
sinon . stub ( pool , 'release' ) ;
332
322
redisCache . set ( 'foo' , 'bar' , function ( ) {
333
323
redisCache . keys ( 'f*' , function ( err ) {
334
- pool . acquire . restore ( ) ;
324
+ pool . acquireDb . restore ( ) ;
335
325
pool . release . restore ( ) ;
336
326
assert . notEqual ( err , null ) ;
337
327
done ( ) ;
@@ -341,16 +331,16 @@ describe('keys', function () {
341
331
} ) ;
342
332
343
333
describe ( 'isCacheableValue' , function ( ) {
344
- it ( 'should return true when the value is not null or undefined' , function ( done ) {
334
+ it ( 'should return true when the value is not undefined' , function ( done ) {
345
335
assert . equal ( redisCache . store . isCacheableValue ( 0 ) , true ) ;
346
336
assert . equal ( redisCache . store . isCacheableValue ( 100 ) , true ) ;
347
337
assert . equal ( redisCache . store . isCacheableValue ( '' ) , true ) ;
348
338
assert . equal ( redisCache . store . isCacheableValue ( 'test' ) , true ) ;
339
+ assert . equal ( redisCache . store . isCacheableValue ( null ) , true ) ;
349
340
done ( ) ;
350
341
} ) ;
351
342
352
- it ( 'should return false when the value is null or undefined' , function ( done ) {
353
- assert . equal ( redisCache . store . isCacheableValue ( null ) , false ) ;
343
+ it ( 'should return false when the value is undefined' , function ( done ) {
354
344
assert . equal ( redisCache . store . isCacheableValue ( undefined ) , false ) ;
355
345
done ( ) ;
356
346
} ) ;
@@ -378,10 +368,10 @@ describe('getClient', function () {
378
368
379
369
it ( 'should return an error if there is an error acquiring a connection' , function ( done ) {
380
370
var pool = redisCache . store . _pool ;
381
- sinon . stub ( pool , 'acquire ' ) . yieldsAsync ( 'Something unexpected' ) ;
371
+ sinon . stub ( pool , 'acquireDb ' ) . yieldsAsync ( 'Something unexpected' ) ;
382
372
sinon . stub ( pool , 'release' ) ;
383
373
redisCache . store . getClient ( function ( err ) {
384
- pool . acquire . restore ( ) ;
374
+ pool . acquireDb . restore ( ) ;
385
375
pool . release . restore ( ) ;
386
376
assert . notEqual ( err , null ) ;
387
377
done ( ) ;
0 commit comments