@@ -4,14 +4,22 @@ import chaiAsPromised = require('chai-as-promised');
4
4
import * as mock from 'ts-mockito' ;
5
5
6
6
import http = require( 'http' ) ;
7
+ import { Duplex } from 'stream' ;
8
+ import { EventEmitter } from 'ws' ;
7
9
8
10
import { V1Namespace , V1NamespaceList , V1ObjectMeta , V1Pod , V1ListMeta } from './api' ;
9
11
import { deleteObject , ListWatch , deleteItems } from './cache' ;
10
- import { ListCallback , ADD , UPDATE , DELETE , ListPromise } from './informer' ;
12
+ import { ADD , UPDATE , DELETE , ListPromise } from './informer' ;
11
13
12
14
use ( chaiAsPromised ) ;
13
15
14
- import { Watch } from './watch' ;
16
+ import { RequestResult , Watch } from './watch' ;
17
+
18
+ // Object replacing real Request object in the test
19
+ class FakeRequest extends EventEmitter implements RequestResult {
20
+ pipe ( stream : Duplex ) : void { }
21
+ abort ( ) { }
22
+ }
15
23
16
24
describe ( 'ListWatchCache' , ( ) => {
17
25
it ( 'should throw on unknown update' , ( ) => {
@@ -24,7 +32,12 @@ describe('ListWatchCache', () => {
24
32
( resolve , reject ) => {
25
33
resolve ( {
26
34
response : { } as http . IncomingMessage ,
27
- body : { } as V1NamespaceList ,
35
+ body : {
36
+ metadata : {
37
+ resourceVersion : '12345' ,
38
+ } as V1ListMeta ,
39
+ items : [ ] ,
40
+ } as V1NamespaceList ,
28
41
} ) ;
29
42
} ,
30
43
) ;
@@ -88,15 +101,9 @@ describe('ListWatchCache', () => {
88
101
} ;
89
102
const promise = new Promise ( ( resolve ) => {
90
103
mock . when (
91
- fakeWatch . watch (
92
- mock . anything ( ) ,
93
- mock . anything ( ) ,
94
- mock . anything ( ) ,
95
- mock . anything ( ) ,
96
- mock . anything ( ) ,
97
- ) ,
104
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
98
105
) . thenCall ( ( ) => {
99
- resolve ( null ) ;
106
+ resolve ( new FakeRequest ( ) ) ;
100
107
} ) ;
101
108
} ) ;
102
109
const cache = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn ) ;
@@ -159,7 +166,7 @@ describe('ListWatchCache', () => {
159
166
} as V1ObjectMeta ,
160
167
} as V1Namespace ) ;
161
168
162
- await doneHandler ( ) ;
169
+ await doneHandler ( null ) ;
163
170
expect ( cache . list ( ) . length , 'all namespace list' ) . to . equal ( 1 ) ;
164
171
expect ( cache . list ( 'default' ) . length , 'default namespace list' ) . to . equal ( 1 ) ;
165
172
expect ( cache . list ( 'other' ) , 'other namespace list' ) . to . be . undefined ;
@@ -198,15 +205,9 @@ describe('ListWatchCache', () => {
198
205
} ;
199
206
const promise = new Promise ( ( resolve ) => {
200
207
mock . when (
201
- fakeWatch . watch (
202
- mock . anything ( ) ,
203
- mock . anything ( ) ,
204
- mock . anything ( ) ,
205
- mock . anything ( ) ,
206
- mock . anything ( ) ,
207
- ) ,
208
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
208
209
) . thenCall ( ( ) => {
209
- resolve ( null ) ;
210
+ resolve ( new FakeRequest ( ) ) ;
210
211
} ) ;
211
212
} ) ;
212
213
const informer = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn ) ;
@@ -285,15 +286,9 @@ describe('ListWatchCache', () => {
285
286
} ;
286
287
const promise = new Promise ( ( resolve ) => {
287
288
mock . when (
288
- fakeWatch . watch (
289
- mock . anything ( ) ,
290
- mock . anything ( ) ,
291
- mock . anything ( ) ,
292
- mock . anything ( ) ,
293
- mock . anything ( ) ,
294
- ) ,
289
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
295
290
) . thenCall ( ( ) => {
296
- resolve ( null ) ;
291
+ resolve ( new FakeRequest ( ) ) ;
297
292
} ) ;
298
293
} ) ;
299
294
const informer = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn ) ;
@@ -362,15 +357,9 @@ describe('ListWatchCache', () => {
362
357
} ;
363
358
let promise = new Promise ( ( resolve ) => {
364
359
mock . when (
365
- fakeWatch . watch (
366
- mock . anything ( ) ,
367
- mock . anything ( ) ,
368
- mock . anything ( ) ,
369
- mock . anything ( ) ,
370
- mock . anything ( ) ,
371
- ) ,
360
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
372
361
) . thenCall ( ( ) => {
373
- resolve ( null ) ;
362
+ resolve ( new FakeRequest ( ) ) ;
374
363
} ) ;
375
364
} ) ;
376
365
const informer = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn , false ) ;
@@ -390,18 +379,12 @@ describe('ListWatchCache', () => {
390
379
391
380
promise = new Promise ( ( resolve ) => {
392
381
mock . when (
393
- fakeWatch . watch (
394
- mock . anything ( ) ,
395
- mock . anything ( ) ,
396
- mock . anything ( ) ,
397
- mock . anything ( ) ,
398
- mock . anything ( ) ,
399
- ) ,
382
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
400
383
) . thenCall ( ( ) => {
401
- resolve ( null ) ;
384
+ resolve ( new FakeRequest ( ) ) ;
402
385
} ) ;
403
386
} ) ;
404
- doneHandler ( ) ;
387
+ doneHandler ( null ) ;
405
388
await promise ;
406
389
expect ( addObjects ) . to . deep . equal ( list ) ;
407
390
expect ( updateObjects ) . to . deep . equal ( list ) ;
@@ -447,15 +430,9 @@ describe('ListWatchCache', () => {
447
430
} ;
448
431
let promise = new Promise ( ( resolve ) => {
449
432
mock . when (
450
- fakeWatch . watch (
451
- mock . anything ( ) ,
452
- mock . anything ( ) ,
453
- mock . anything ( ) ,
454
- mock . anything ( ) ,
455
- mock . anything ( ) ,
456
- ) ,
433
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
457
434
) . thenCall ( ( ) => {
458
- resolve ( null ) ;
435
+ resolve ( new FakeRequest ( ) ) ;
459
436
} ) ;
460
437
} ) ;
461
438
const informer = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn , false ) ;
@@ -476,19 +453,13 @@ describe('ListWatchCache', () => {
476
453
477
454
promise = new Promise ( ( resolve ) => {
478
455
mock . when (
479
- fakeWatch . watch (
480
- mock . anything ( ) ,
481
- mock . anything ( ) ,
482
- mock . anything ( ) ,
483
- mock . anything ( ) ,
484
- mock . anything ( ) ,
485
- ) ,
456
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
486
457
) . thenCall ( ( ) => {
487
- resolve ( null ) ;
458
+ resolve ( new FakeRequest ( ) ) ;
488
459
} ) ;
489
460
} ) ;
490
461
listObj . items = list2 ;
491
- doneHandler ( ) ;
462
+ doneHandler ( null ) ;
492
463
await promise ;
493
464
expect ( addObjects ) . to . deep . equal ( list ) ;
494
465
expect ( updateObjects ) . to . deep . equal ( list2 ) ;
@@ -536,15 +507,9 @@ describe('ListWatchCache', () => {
536
507
} ;
537
508
const promise = new Promise ( ( resolve ) => {
538
509
mock . when (
539
- fakeWatch . watch (
540
- mock . anything ( ) ,
541
- mock . anything ( ) ,
542
- mock . anything ( ) ,
543
- mock . anything ( ) ,
544
- mock . anything ( ) ,
545
- ) ,
510
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
546
511
) . thenCall ( ( ) => {
547
- resolve ( null ) ;
512
+ resolve ( new FakeRequest ( ) ) ;
548
513
} ) ;
549
514
} ) ;
550
515
const cache = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn ) ;
@@ -662,13 +627,7 @@ describe('ListWatchCache', () => {
662
627
} ;
663
628
const watchCalled = new Promise ( ( resolve ) => {
664
629
mock . when (
665
- fakeWatch . watch (
666
- mock . anything ( ) ,
667
- mock . anything ( ) ,
668
- mock . anything ( ) ,
669
- mock . anything ( ) ,
670
- mock . anything ( ) ,
671
- ) ,
630
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
672
631
) . thenCall ( resolve ) ;
673
632
} ) ;
674
633
const informer = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn ) ;
@@ -727,13 +686,7 @@ describe('ListWatchCache', () => {
727
686
} ;
728
687
const watchCalled = new Promise ( ( resolve ) => {
729
688
mock . when (
730
- fakeWatch . watch (
731
- mock . anything ( ) ,
732
- mock . anything ( ) ,
733
- mock . anything ( ) ,
734
- mock . anything ( ) ,
735
- mock . anything ( ) ,
736
- ) ,
689
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
737
690
) . thenCall ( resolve ) ;
738
691
} ) ;
739
692
const informer = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn ) ;
@@ -820,13 +773,7 @@ describe('ListWatchCache', () => {
820
773
} ;
821
774
const watchCalled = new Promise ( ( resolve ) => {
822
775
mock . when (
823
- fakeWatch . watch (
824
- mock . anything ( ) ,
825
- mock . anything ( ) ,
826
- mock . anything ( ) ,
827
- mock . anything ( ) ,
828
- mock . anything ( ) ,
829
- ) ,
776
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
830
777
) . thenCall ( resolve ) ;
831
778
} ) ;
832
779
const informer = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn ) ;
0 commit comments