UNPKG

22.7 kBJavaScriptView Raw
1const tap = require('tap')
2 , sinon = require('sinon')
3 , util = require('abstract-object/lib/util')
4 , testCommon = require('./testCommon')
5 , AbstractLevelDOWN = require('./').AbstractLevelDOWN
6 , AbstractIterator = require('./').AbstractIterator
7 , AbstractChainedBatch = require('./').AbstractChainedBatch
8
9
10function factory (location) {
11 return new AbstractLevelDOWN(location)
12}
13
14/*** compatibility with basic LevelDOWN API ***/
15
16require('./abstract/error-test').all(factory, tap.test, testCommon)
17
18require('./abstract/leveldown-test').args(factory, tap.test, testCommon)
19
20require('./abstract/open-test').args(factory, tap.test, testCommon)
21
22require('./abstract/del-test').setUp(factory, tap.test, testCommon)
23require('./abstract/del-test').args(tap.test)
24
25require('./abstract/isExists-test').setUp(factory, tap.test, testCommon)
26require('./abstract/isExists-test').args(tap.test)
27
28require('./abstract/get-test').setUp(factory, tap.test, testCommon)
29require('./abstract/get-test').args(tap.test)
30
31require('./abstract/getbuffer-test').setUp(factory, tap.test, testCommon)
32require('./abstract/getbuffer-test').args(tap.test)
33
34require('./abstract/mget-test').setUp(factory, tap.test, testCommon)
35require('./abstract/mget-test').args(tap.test)
36
37require('./abstract/put-test').setUp(factory, tap.test, testCommon)
38require('./abstract/put-test').args(tap.test)
39
40require('./abstract/put-get-del-test').setUp(factory, tap.test, testCommon)
41require('./abstract/put-get-del-test').errorKeys(tap.test)
42//require('./abstract/put-get-del-test').nonErrorKeys(tap.test, testCommon)
43require('./abstract/put-get-del-test').errorValues(tap.test)
44//require('./abstract/test/put-get-del-test').nonErrorKeys(tap.test, testCommon)
45require('./abstract/put-get-del-test').tearDown(tap.test, testCommon)
46
47require('./abstract/approximate-size-test').setUp(factory, tap.test, testCommon)
48require('./abstract/approximate-size-test').args(tap.test)
49
50require('./abstract/batch-test').setUp(factory, tap.test, testCommon)
51require('./abstract/batch-test').args(tap.test)
52
53require('./abstract/chained-batch-test').setUp(factory, tap.test, testCommon)
54require('./abstract/chained-batch-test').args(tap.test)
55
56require('./abstract/close-test').close(factory, tap.test, testCommon)
57
58require('./abstract/iterator-test').setUp(factory, tap.test, testCommon)
59require('./abstract/iterator-test').args(tap.test)
60require('./abstract/iterator-test').sequence(tap.test)
61
62/*** extensibility ***/
63
64tap.test('test core extensibility', function (t) {
65 function Test (location) {
66 AbstractLevelDOWN.call(this, location)
67 t.equal(this.location, location, 'location set on `this`')
68 t.end()
69 }
70
71 util.inherits(Test, AbstractLevelDOWN)
72
73 ;new Test('foobar')
74})
75
76tap.test('test core init extensibility', function (t) {
77 function Test (location) {
78 }
79 Test.prototype.init = function(location) {
80 Test.__super__.init.call(this, location);
81 t.equal(this.location, location, 'location set on `this`')
82 t.end()
83 }
84
85 util.inherits(Test, AbstractLevelDOWN)
86
87 ; util.createObject(Test, 'foobar')
88})
89
90tap.test('test open() extensibility', function (t) {
91 var spy = sinon.spy()
92 , expectedCb = function () {}
93 , expectedOptions = { createIfMissing: true, errorIfExists: false }
94 , test
95
96 function Test (location) {
97 AbstractLevelDOWN.call(this, location)
98 }
99
100 util.inherits(Test, AbstractLevelDOWN)
101
102 Test.prototype._open = spy
103
104 test = new Test('foobar')
105 test.open(expectedCb)
106
107 t.equal(spy.callCount, 1, 'got _open() call')
108 t.equal(spy.getCall(0).thisValue, test, '`this` on _open() was correct')
109 t.equal(spy.getCall(0).args.length, 2, 'got two arguments')
110 t.deepEqual(spy.getCall(0).args[0], expectedOptions, 'got default options argument')
111 //t.equal(spy.getCall(0).args[1], expectedCb, 'got expected cb argument')
112
113 test.open({ options: 1 }, expectedCb)
114
115 expectedOptions.options = 1
116
117 t.equal(spy.callCount, 2, 'got _open() call')
118 t.equal(spy.getCall(1).thisValue, test, '`this` on _open() was correct')
119 t.equal(spy.getCall(1).args.length, 2, 'got two arguments')
120 t.deepEqual(spy.getCall(1).args[0], expectedOptions, 'got expected options argument')
121 //t.equal(spy.getCall(1).args[1], expectedCb, 'got expected cb argument')
122 t.end()
123})
124
125tap.test('test close() extensibility', function (t) {
126 var spy = sinon.spy()
127 , expectedCb = function () {}
128 , test
129
130 function Test (location) {
131 AbstractLevelDOWN.call(this, location)
132 }
133
134 util.inherits(Test, AbstractLevelDOWN)
135
136 Test.prototype._close = spy
137
138 test = new Test('foobar')
139 test.close(expectedCb)
140
141 t.equal(spy.callCount, 1, 'got _close() call')
142 t.equal(spy.getCall(0).thisValue, test, '`this` on _close() was correct')
143 t.equal(spy.getCall(0).args.length, 1, 'got one arguments')
144 //t.equal(spy.getCall(0).args[0], expectedCb, 'got expected cb argument')
145 t.end()
146})
147
148tap.test('test get() extensibility', function (t) {
149 var spy = sinon.spy()
150 , expectedCb = function () {}
151 , expectedOptions = { asBuffer: true }
152 , expectedKey = 'a key'
153 , test
154
155 function Test (location) {
156 AbstractLevelDOWN.call(this, location)
157 }
158
159 util.inherits(Test, AbstractLevelDOWN)
160
161 Test.prototype._get = spy
162
163 test = new Test('foobar')
164 test.get(expectedKey, expectedCb)
165
166 t.equal(spy.callCount, 1, 'got _get() call')
167 t.equal(spy.getCall(0).thisValue, test, '`this` on _get() was correct')
168 t.equal(spy.getCall(0).args.length, 3, 'got three arguments')
169 t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
170 t.deepEqual(spy.getCall(0).args[1], expectedOptions, 'got default options argument')
171 t.equal(spy.getCall(0).args[2], expectedCb, 'got expected cb argument')
172
173 test.get(expectedKey, { options: 1 }, expectedCb)
174
175 expectedOptions.options = 1
176
177 t.equal(spy.callCount, 2, 'got _get() call')
178 t.equal(spy.getCall(1).thisValue, test, '`this` on _get() was correct')
179 t.equal(spy.getCall(1).args.length, 3, 'got three arguments')
180 t.equal(spy.getCall(1).args[0], expectedKey, 'got expected key argument')
181 t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')
182 t.equal(spy.getCall(1).args[2], expectedCb, 'got expected cb argument')
183 t.end()
184})
185
186tap.test('test getbuffer() extensibility', function (t) {
187 var spy = sinon.spy()
188 , expectedCb = function () {}
189 , expectedBuffer = new Buffer(12)
190 , expectedOptions = {offset:0 }
191 , expectedKey = 'a key'
192 , test
193
194 function Test (location) {
195 AbstractLevelDOWN.call(this, location)
196 }
197
198 util.inherits(Test, AbstractLevelDOWN)
199
200 Test.prototype._getBuffer = spy
201
202 test = new Test('foobar')
203 test.getBuffer(expectedKey, expectedBuffer, expectedCb)
204
205 t.equal(spy.callCount, 1, 'got _getBuffer() call')
206 t.equal(spy.getCall(0).thisValue, test, '`this` on _getBuffer() was correct')
207 t.equal(spy.getCall(0).args.length, 4, 'got four arguments')
208 t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
209 t.equal(spy.getCall(0).args[1], expectedBuffer, 'got expected destBuffer argument')
210 t.deepEqual(spy.getCall(0).args[2], expectedOptions, 'got default options argument')
211 t.equal(spy.getCall(0).args[3], expectedCb, 'got expected cb argument')
212
213 test.getBuffer(expectedKey, expectedBuffer, { options: 1 }, expectedCb)
214
215 expectedOptions.options = 1
216
217 t.equal(spy.callCount, 2, 'got _getBuffer() call')
218 t.equal(spy.getCall(1).thisValue, test, '`this` on _getBuffer() was correct')
219 t.equal(spy.getCall(1).args.length, 4, 'got four arguments')
220 t.equal(spy.getCall(1).args[0], expectedKey, 'got expected key argument')
221 t.equal(spy.getCall(1).args[1], expectedBuffer, 'got expected destBuffer argument')
222 t.deepEqual(spy.getCall(1).args[2], expectedOptions, 'got options argument')
223 t.equal(spy.getCall(1).args[3], expectedCb, 'got expected cb argument')
224 t.end()
225})
226
227tap.test('test mGet() extensibility', function (t) {
228 var spy = sinon.spy()
229 , expectedCb = function () {}
230 , expectedOptions = { asBuffer: false, raiseError: true }
231 , expectedKey = ['a key']
232 , test
233
234 function Test (location) {
235 AbstractLevelDOWN.call(this, location)
236 }
237
238 util.inherits(Test, AbstractLevelDOWN)
239
240 Test.prototype._mGet = spy
241
242 test = new Test('foobar')
243 test.mGet(expectedKey, expectedCb)
244
245 t.equal(spy.callCount, 1, 'got _mGet() call')
246 t.equal(spy.getCall(0).thisValue, test, '`this` on _mGet() was correct')
247 t.equal(spy.getCall(0).args.length, 3, 'got three arguments')
248 t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
249 t.deepEqual(spy.getCall(0).args[1], expectedOptions, 'got default options argument')
250 //t.equal(spy.getCall(0).args[2], expectedCb, 'got expected cb argument')
251
252 test.mGet(expectedKey, { options: 1 }, expectedCb)
253
254 expectedOptions.options = 1
255
256 t.equal(spy.callCount, 2, 'got _mGet() call')
257 t.equal(spy.getCall(1).thisValue, test, '`this` on _mGet() was correct')
258 t.equal(spy.getCall(1).args.length, 3, 'got three arguments')
259 t.equal(spy.getCall(1).args[0], expectedKey, 'got expected key argument')
260 t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')
261 //t.equal(spy.getCall(1).args[2], expectedCb, 'got expected cb argument')
262 t.end()
263})
264
265tap.test('test del() extensibility', function (t) {
266 var spy = sinon.spy()
267 , expectedCb = function () {}
268 , expectedOptions = { options: 1 }
269 , expectedKey = 'a key'
270 , test
271
272 function Test (location) {
273 AbstractLevelDOWN.call(this, location)
274 }
275
276 util.inherits(Test, AbstractLevelDOWN)
277
278 Test.prototype._del = spy
279
280 test = new Test('foobar')
281 test.del(expectedKey, expectedCb)
282
283 t.equal(spy.callCount, 1, 'got _del() call')
284 t.equal(spy.getCall(0).thisValue, test, '`this` on _del() was correct')
285 t.equal(spy.getCall(0).args.length, 3, 'got three arguments')
286 t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
287 t.deepEqual(spy.getCall(0).args[1], {}, 'got blank options argument')
288 t.equal(spy.getCall(0).args[2], expectedCb, 'got expected cb argument')
289
290 test.del(expectedKey, expectedOptions, expectedCb)
291
292 t.equal(spy.callCount, 2, 'got _del() call')
293 t.equal(spy.getCall(1).thisValue, test, '`this` on _del() was correct')
294 t.equal(spy.getCall(1).args.length, 3, 'got three arguments')
295 t.equal(spy.getCall(1).args[0], expectedKey, 'got expected key argument')
296 t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')
297 t.equal(spy.getCall(1).args[2], expectedCb, 'got expected cb argument')
298 t.end()
299})
300
301tap.test('test put() extensibility', function (t) {
302 var spy = sinon.spy()
303 , expectedCb = function () {}
304 , expectedOptions = { options: 1 }
305 , expectedKey = 'a key'
306 , expectedValue = 'a value'
307 , test
308
309 function Test (location) {
310 AbstractLevelDOWN.call(this, location)
311 }
312
313 util.inherits(Test, AbstractLevelDOWN)
314
315 Test.prototype._put = spy
316
317 test = new Test('foobar')
318 test.put(expectedKey, expectedValue, expectedCb)
319
320 t.equal(spy.callCount, 1, 'got _put() call')
321 t.equal(spy.getCall(0).thisValue, test, '`this` on _put() was correct')
322 t.equal(spy.getCall(0).args.length, 4, 'got four arguments')
323 t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
324 t.equal(spy.getCall(0).args[1], expectedValue, 'got expected value argument')
325 t.deepEqual(spy.getCall(0).args[2], {}, 'got blank options argument')
326 t.equal(spy.getCall(0).args[3], expectedCb, 'got expected cb argument')
327
328 test.put(expectedKey, expectedValue, expectedOptions, expectedCb)
329
330 t.equal(spy.callCount, 2, 'got _put() call')
331 t.equal(spy.getCall(1).thisValue, test, '`this` on _put() was correct')
332 t.equal(spy.getCall(1).args.length, 4, 'got four arguments')
333 t.equal(spy.getCall(1).args[0], expectedKey, 'got expected key argument')
334 t.equal(spy.getCall(1).args[1], expectedValue, 'got expected value argument')
335 t.deepEqual(spy.getCall(1).args[2], expectedOptions, 'got blank options argument')
336 t.equal(spy.getCall(1).args[3], expectedCb, 'got expected cb argument')
337 t.end()
338})
339
340tap.test('test approximateSize() extensibility', function (t) {
341 var spy = sinon.spy()
342 , expectedCb = function () {}
343 , expectedStart = 'a start'
344 , expectedEnd = 'an end'
345 , test
346
347 function Test (location) {
348 AbstractLevelDOWN.call(this, location)
349 }
350
351 util.inherits(Test, AbstractLevelDOWN)
352
353 Test.prototype._approximateSize = spy
354
355 test = new Test('foobar')
356 test.approximateSize(expectedStart, expectedEnd, expectedCb)
357
358 t.equal(spy.callCount, 1, 'got _approximateSize() call')
359 t.equal(spy.getCall(0).thisValue, test, '`this` on _approximateSize() was correct')
360 t.equal(spy.getCall(0).args.length, 3, 'got three arguments')
361 t.equal(spy.getCall(0).args[0], expectedStart, 'got expected start argument')
362 t.equal(spy.getCall(0).args[1], expectedEnd, 'got expected end argument')
363 t.equal(spy.getCall(0).args[2], expectedCb, 'got expected cb argument')
364 t.end()
365})
366
367tap.test('test batch() extensibility', function (t) {
368 var spy = sinon.spy()
369 , expectedCb = function () {}
370 , expectedOptions = { options: 1 }
371 , expectedArray = [ 1, 2 ]
372 , test
373
374 function Test (location) {
375 AbstractLevelDOWN.call(this, location)
376 }
377
378 util.inherits(Test, AbstractLevelDOWN)
379
380 Test.prototype._batch = spy
381
382 test = new Test('foobar')
383
384 test.batch(expectedArray, expectedCb)
385
386 t.equal(spy.callCount, 1, 'got _batch() call')
387 t.equal(spy.getCall(0).thisValue, test, '`this` on _batch() was correct')
388 t.equal(spy.getCall(0).args.length, 3, 'got three arguments')
389 t.equal(spy.getCall(0).args[0], expectedArray, 'got expected array argument')
390 t.deepEqual(spy.getCall(0).args[1], {}, 'got expected options argument')
391 t.equal(spy.getCall(0).args[2], expectedCb, 'got expected callback argument')
392
393 test.batch(expectedArray, expectedOptions, expectedCb)
394
395 t.equal(spy.callCount, 2, 'got _batch() call')
396 t.equal(spy.getCall(1).thisValue, test, '`this` on _batch() was correct')
397 t.equal(spy.getCall(1).args.length, 3, 'got three arguments')
398 t.equal(spy.getCall(1).args[0], expectedArray, 'got expected array argument')
399 t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')
400 t.equal(spy.getCall(1).args[2], expectedCb, 'got expected callback argument')
401
402 test.batch(expectedArray, null, expectedCb)
403
404 t.equal(spy.callCount, 3, 'got _batch() call')
405 t.equal(spy.getCall(2).thisValue, test, '`this` on _batch() was correct')
406 t.equal(spy.getCall(2).args.length, 3, 'got three arguments')
407 t.equal(spy.getCall(2).args[0], expectedArray, 'got expected array argument')
408 t.ok(spy.getCall(2).args[1], 'options should not be null')
409 t.equal(spy.getCall(2).args[2], expectedCb, 'got expected callback argument')
410 t.end()
411})
412
413tap.test('test chained batch() (array) extensibility', function (t) {
414 var spy = sinon.spy()
415 , expectedCb = function () {}
416 , expectedOptions = { options: 1 }
417 , expectedArray = [ 1, 2 ]
418 , test
419
420 function Test (location) {
421 AbstractLevelDOWN.call(this, location)
422 }
423
424 util.inherits(Test, AbstractLevelDOWN)
425
426 Test.prototype._batch = spy
427
428 test = new Test('foobar')
429
430 test.batch().put('foo', 'bar').del('bang').write(expectedCb)
431
432 t.equal(spy.callCount, 1, 'got _batch() call')
433 t.equal(spy.getCall(0).thisValue, test, '`this` on _batch() was correct')
434 t.equal(spy.getCall(0).args.length, 3, 'got three arguments')
435 t.equal(spy.getCall(0).args[0].length, 2, 'got expected array argument')
436 t.deepEqual(spy.getCall(0).args[0][0], { type: 'put', key: 'foo', value: 'bar' }, 'got expected array argument[0]')
437 t.deepEqual(spy.getCall(0).args[0][1], { type: 'del', key: 'bang' }, 'got expected array argument[1]')
438 t.deepEqual(spy.getCall(0).args[1], {}, 'got expected options argument')
439 t.equal(spy.getCall(0).args[2], expectedCb, 'got expected callback argument')
440
441 test.batch().put('foo', 'bar').del('bang').write(expectedOptions, expectedCb)
442
443 t.equal(spy.callCount, 2, 'got _batch() call')
444 t.equal(spy.getCall(1).thisValue, test, '`this` on _batch() was correct')
445 t.equal(spy.getCall(1).args.length, 3, 'got three arguments')
446 t.equal(spy.getCall(1).args[0].length, 2, 'got expected array argument')
447 t.deepEqual(spy.getCall(1).args[0][0], { type: 'put', key: 'foo', value: 'bar' }, 'got expected array argument[0]')
448 t.deepEqual(spy.getCall(1).args[0][1], { type: 'del', key: 'bang' }, 'got expected array argument[1]')
449 t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')
450 t.equal(spy.getCall(1).args[2], expectedCb, 'got expected callback argument')
451
452 t.end()
453})
454
455tap.test('test chained batch() (custom _chainedBatch) extensibility', function (t) {
456 var spy = sinon.spy()
457 , test
458
459 function Test (location) {
460 AbstractLevelDOWN.call(this, location)
461 }
462
463 util.inherits(Test, AbstractLevelDOWN)
464
465 Test.prototype._chainedBatch = spy
466
467 test = new Test('foobar')
468
469 test.batch()
470
471 t.equal(spy.callCount, 1, 'got _chainedBatch() call')
472 t.equal(spy.getCall(0).thisValue, test, '`this` on _chainedBatch() was correct')
473
474 test.batch()
475
476 t.equal(spy.callCount, 2, 'got _chainedBatch() call')
477 t.equal(spy.getCall(1).thisValue, test, '`this` on _chainedBatch() was correct')
478
479 t.end()
480})
481
482tap.test('test AbstractChainedBatch extensibility', function (t) {
483 function Test (db) {
484 AbstractChainedBatch.call(this, db)
485 t.equal(this._db, db, 'db set on `this`')
486 t.end()
487 }
488
489 util.inherits(Test, AbstractChainedBatch)
490
491 new Test('foobar')
492})
493
494tap.test('test write() extensibility', function (t) {
495 var spy = sinon.spy()
496 , spycb = sinon.spy()
497 , test
498
499 function Test (db) {
500 AbstractChainedBatch.call(this, db)
501 }
502
503 util.inherits(Test, AbstractChainedBatch)
504
505 Test.prototype._write = spy
506
507 test = new Test('foobar')
508 test.write(spycb)
509
510 t.equal(spy.callCount, 1, 'got _write() call')
511 t.equal(spy.getCall(0).thisValue, test, '`this` on _write() was correct')
512 t.equal(spy.getCall(0).args.length, 1, 'got one argument')
513 // awkward here cause of nextTick & an internal wrapped cb
514 t.type(spy.getCall(0).args[0], 'function', 'got a callback function')
515 t.equal(spycb.callCount, 0, 'spycb not called')
516 spy.getCall(0).args[0]()
517 t.equal(spycb.callCount, 1, 'spycb called, i.e. was our cb argument')
518 t.end()
519})
520
521tap.test('test put() extensibility', function (t) {
522 var spy = sinon.spy()
523 , expectedKey = 'key'
524 , expectedValue = 'value'
525 , returnValue
526 , test
527
528 function Test (db) {
529 AbstractChainedBatch.call(this, db)
530 }
531
532 util.inherits(Test, AbstractChainedBatch)
533
534 Test.prototype._put = spy
535
536 test = new Test(factory('foobar'))
537 returnValue = test.put(expectedKey, expectedValue)
538 t.equal(spy.callCount, 1, 'got _put call')
539 t.equal(spy.getCall(0).thisValue, test, '`this` on _put() was correct')
540 t.equal(spy.getCall(0).args.length, 2, 'got two arguments')
541 t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
542 t.equal(spy.getCall(0).args[1], expectedValue, 'got expected value argument')
543 t.equal(returnValue, test, 'get expected return value')
544 t.end()
545})
546
547tap.test('test del() extensibility', function (t) {
548 var spy = sinon.spy()
549 , expectedKey = 'key'
550 , returnValue
551 , test
552
553 function Test (db) {
554 AbstractChainedBatch.call(this, db)
555 }
556
557 util.inherits(Test, AbstractChainedBatch)
558
559 Test.prototype._del = spy
560
561 test = new Test(factory('foobar'))
562 returnValue = test.del(expectedKey)
563 t.equal(spy.callCount, 1, 'got _del call')
564 t.equal(spy.getCall(0).thisValue, test, '`this` on _del() was correct')
565 t.equal(spy.getCall(0).args.length, 1, 'got one argument')
566 t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
567 t.equal(returnValue, test, 'get expected return value')
568 t.end()
569})
570
571tap.test('test clear() extensibility', function (t) {
572 var spy = sinon.spy()
573 , returnValue
574 , test
575
576 function Test (db) {
577 AbstractChainedBatch.call(this, db)
578 }
579
580 util.inherits(Test, AbstractChainedBatch)
581
582 Test.prototype._clear = spy
583
584 test = new Test(factory('foobar'))
585 returnValue = test.clear()
586 t.equal(spy.callCount, 1, 'got _clear call')
587 t.equal(spy.getCall(0).thisValue, test, '`this` on _clear() was correct')
588 t.equal(spy.getCall(0).args.length, 0, 'got zero arguments')
589 t.equal(returnValue, test, 'get expected return value')
590 t.end()
591})
592
593tap.test('test iterator() extensibility', function (t) {
594 var spy = sinon.spy()
595 , expectedOptions = { options: 1, reverse: false, keys: true, values: true, limit: -1, keyAsBuffer: false, valueAsBuffer: false }
596 , test
597
598 function Test (location) {
599 AbstractLevelDOWN.call(this, location)
600 }
601
602 util.inherits(Test, AbstractLevelDOWN)
603
604 Test.prototype._iterator = spy
605
606 test = new Test('foobar')
607 test.iterator({ options: 1 })
608
609 t.equal(spy.callCount, 1, 'got _close() call')
610 t.equal(spy.getCall(0).thisValue, test, '`this` on _close() was correct')
611 t.equal(spy.getCall(0).args.length, 1, 'got one arguments')
612 t.deepEqual(spy.getCall(0).args[0], expectedOptions, 'got expected options argument')
613 t.end()
614})
615
616tap.test('test AbstractIterator extensibility', function (t) {
617 function Test (db) {
618 AbstractIterator.call(this, db)
619 t.equal(this.db, db, 'db set on `this`')
620 t.end()
621 }
622
623 util.inherits(Test, AbstractIterator)
624
625 ;new Test('foobar')
626})
627
628tap.test('test next() extensibility', function (t) {
629 var spy = sinon.spy()
630 , spycb = sinon.spy()
631 , test
632
633 function Test (db) {
634 AbstractIterator.call(this, db)
635 }
636
637 util.inherits(Test, AbstractIterator)
638
639 Test.prototype._next = spy
640
641 test = new Test('foobar')
642 test.next(spycb)
643
644 t.equal(spy.callCount, 1, 'got _next() call')
645 t.equal(spy.getCall(0).thisValue, test, '`this` on _next() was correct')
646 t.equal(spy.getCall(0).args.length, 1, 'got one arguments')
647 // awkward here cause of nextTick & an internal wrapped cb
648 t.type(spy.getCall(0).args[0], 'function', 'got a callback function')
649 t.equal(spycb.callCount, 0, 'spycb not called')
650 spy.getCall(0).args[0]()
651 t.equal(spycb.callCount, 1, 'spycb called, i.e. was our cb argument')
652 t.end()
653})
654
655tap.test('test end() extensibility', function (t) {
656 var spy = sinon.spy()
657 , expectedCb = function () {}
658 , test
659
660 function Test (db) {
661 AbstractIterator.call(this, db)
662 }
663
664 util.inherits(Test, AbstractIterator)
665
666 Test.prototype._end = spy
667
668 test = new Test('foobar')
669 test.end(expectedCb)
670
671 t.equal(spy.callCount, 1, 'got _end() call')
672 t.equal(spy.getCall(0).thisValue, test, '`this` on _end() was correct')
673 t.equal(spy.getCall(0).args.length, 1, 'got one arguments')
674 t.equal(spy.getCall(0).args[0], expectedCb, 'got expected cb argument')
675 t.end()
676})