@@ -18,67 +18,103 @@ describe('isReady script', () => {
18
18
process . argv = orgArgs ;
19
19
} ) ;
20
20
describe ( 'Container Logger Checks' , ( ) => {
21
- it ( 'Should check exit with 0 code if container logger is ready' , ( ) => {
21
+ it ( 'Should check exit with 0 code if container logger is ready' , async ( ) => {
22
22
const state = JSON . stringify ( { status : 'ready' , containers : { } } )
23
23
process . argv = [ ] ;
24
- proxyquire ( '../lib/isReady.js' , {
24
+ const terminateSpy = sinon . spy ( ) ;
25
+ const { isReady } = proxyquire ( '../lib/isReady.js' , {
26
+ '@codefresh-io/cf-telemetry/init' : { terminate : terminateSpy } ,
25
27
'fs' : {
26
28
readFileSync : ( ) => Buffer . from ( state ) ,
27
29
} ,
28
30
} ) ;
31
+ await isReady ( ) ;
32
+ expect ( terminateSpy ) . to . have . been . calledOnce ;
29
33
expect ( process . exit ) . to . have . been . calledOnceWith ( 0 ) ;
30
34
} ) ;
31
- it ( 'Should check exit with 1 code if container logger is not ready' , ( ) => {
35
+ it ( 'Should check exit with 1 code if container logger is not ready' , async ( ) => {
32
36
const state = JSON . stringify ( { status : 'notReady' , containers : { } } )
33
37
process . argv = [ ] ;
34
- proxyquire ( '../lib/isReady.js' , {
38
+ const terminateSpy = sinon . spy ( ) ;
39
+ const { isReady } = proxyquire ( '../lib/isReady.js' , {
40
+ '@codefresh-io/cf-telemetry/init' : { terminate : terminateSpy } ,
35
41
'fs' : {
36
42
readFileSync : ( ) => Buffer . from ( state ) ,
37
43
} ,
38
44
} ) ;
45
+ await isReady ( ) ;
46
+ expect ( terminateSpy ) . to . have . been . calledOnce ;
39
47
expect ( process . exit ) . to . have . been . calledOnceWith ( 1 ) ;
40
48
} ) ;
41
49
} ) ;
42
50
describe ( 'Container Checks' , ( ) => {
43
- it ( 'Should check exit with 0 code if container is ready' , ( ) => {
44
- const state = JSON . stringify ( { status : 'ready' , containers : { 'container-id' : { status : ContainerHandlingStatus . LISTENING } } } )
51
+ it ( 'Should check exit with 0 code if container is ready' , async ( ) => {
52
+ const state = JSON . stringify ( {
53
+ status : 'ready' ,
54
+ containers : { 'container-id' : { status : ContainerHandlingStatus . LISTENING } }
55
+ } )
45
56
process . argv = [ 'foo' , 'bar' , 'container-id' ] ;
46
- proxyquire ( '../lib/isReady.js' , {
57
+ const terminateSpy = sinon . spy ( ) ;
58
+ const { isReady} = proxyquire ( '../lib/isReady.js' , {
59
+ '@codefresh-io/cf-telemetry/init' : { terminate : terminateSpy } ,
47
60
'fs' : {
48
61
readFileSync : ( ) => Buffer . from ( state ) ,
49
62
} ,
50
63
} ) ;
64
+ await isReady ( ) ;
65
+ expect ( terminateSpy ) . to . have . been . calledOnce ;
51
66
expect ( process . exit ) . to . have . been . calledOnceWith ( 0 ) ;
52
67
} ) ;
53
- it ( 'Should check exit with 0 code if container is waiting for start status' , ( ) => {
54
- const state = JSON . stringify ( { status : 'ready' , containers : { 'container-id' : { status : ContainerHandlingStatus . WAITING_FOR_START } } } )
68
+ it ( 'Should check exit with 0 code if container is waiting for start status' , async ( ) => {
69
+ const state = JSON . stringify ( {
70
+ status : 'ready' ,
71
+ containers : { 'container-id' : { status : ContainerHandlingStatus . WAITING_FOR_START } }
72
+ } )
55
73
process . argv = [ 'foo' , 'bar' , 'container-id' ] ;
56
- proxyquire ( '../lib/isReady.js' , {
74
+ const terminateSpy = sinon . spy ( ) ;
75
+ const { isReady} = proxyquire ( '../lib/isReady.js' , {
76
+ '@codefresh-io/cf-telemetry/init' : { terminate : terminateSpy } ,
57
77
'fs' : {
58
78
readFileSync : ( ) => Buffer . from ( state ) ,
59
79
} ,
60
80
} ) ;
81
+ await isReady ( ) ;
82
+ expect ( terminateSpy ) . to . have . been . calledOnce ;
61
83
expect ( process . exit ) . to . have . been . calledOnceWith ( 0 ) ;
62
84
} ) ;
63
- it ( 'Should check exit with 0 code if container is finished status' , ( ) => {
64
- const state = JSON . stringify ( { status : 'ready' , containers : { 'container-id' : { status : ContainerHandlingStatus . FINISHED } } } )
85
+ it ( 'Should check exit with 0 code if container is finished status' , async ( ) => {
86
+ const state = JSON . stringify ( {
87
+ status : 'ready' ,
88
+ containers : { 'container-id' : { status : ContainerHandlingStatus . FINISHED } }
89
+ } )
65
90
process . argv = [ 'foo' , 'bar' , 'container-id' ] ;
66
- proxyquire ( '../lib/isReady.js' , {
91
+ const terminateSpy = sinon . spy ( ) ;
92
+ const { isReady} = proxyquire ( '../lib/isReady.js' , {
93
+ '@codefresh-io/cf-telemetry/init' : { terminate : terminateSpy } ,
67
94
'fs' : {
68
95
readFileSync : ( ) => Buffer . from ( state ) ,
69
96
} ,
70
97
} ) ;
98
+ await isReady ( ) ;
99
+ expect ( terminateSpy ) . to . have . been . calledOnce ;
71
100
expect ( process . exit ) . to . have . been . calledOnceWith ( 0 ) ;
72
101
} ) ;
73
- it ( 'Should check exit with 1 code if container is not ready' , ( ) => {
74
- const state = JSON . stringify ( { status : 'ready' , containers : { 'container-id' : { status : ContainerHandlingStatus . INITIALIZING } } } )
102
+ it ( 'Should check exit with 1 code if container is not ready' , async ( ) => {
103
+ const state = JSON . stringify ( {
104
+ status : 'ready' ,
105
+ containers : { 'container-id' : { status : ContainerHandlingStatus . INITIALIZING } }
106
+ } )
75
107
process . argv = [ 'foo' , 'bar' , 'container-id' ] ;
76
- proxyquire ( '../lib/isReady.js' , {
108
+ const terminateSpy = sinon . spy ( ) ;
109
+ const { isReady} = proxyquire ( '../lib/isReady.js' , {
110
+ '@codefresh-io/cf-telemetry/init' : { terminate : terminateSpy } ,
77
111
'fs' : {
78
112
readFileSync : ( ) => Buffer . from ( state ) ,
79
113
} ,
80
114
} ) ;
115
+ await isReady ( ) ;
116
+ expect ( terminateSpy ) . to . have . been . calledOnce ;
81
117
expect ( process . exit ) . to . have . been . calledOnceWith ( 1 ) ;
82
118
} ) ;
83
119
} ) ;
84
- } ) ;
120
+ } ) ;
0 commit comments