@@ -74,7 +74,9 @@ describe('Logger tests', () => {
74
74
it ( 'should start and not listen for existing container in case findExistingContainers param is false' , async ( ) => { // jshint ignore:line
75
75
const taskLogger = { // jshint ignore:line
76
76
on : sinon . spy ( ) ,
77
- restore : sinon . spy ( ( ) => Q . resolve ( ) )
77
+ restore : sinon . spy ( ( ) => Q . resolve ( ) ) ,
78
+ startHealthCheck : sinon . spy ( ) ,
79
+ onHealthCheckReported : sinon . spy ( ) ,
78
80
} ;
79
81
const TaskLoggerFactory = sinon . spy ( ( ) => {
80
82
return Q . resolve ( taskLogger ) ;
@@ -106,11 +108,99 @@ describe('Logger tests', () => {
106
108
107
109
} ) ;
108
110
111
+ it ( 'should report health check status if failed' , async ( ) => { // jshint ignore:line
112
+ let onHealthCheckReportedCb ;
113
+ const onHealthCheckReportedSpy = sinon . spy ( ( func ) => {
114
+ onHealthCheckReportedCb = func ;
115
+ } ) ;
116
+
117
+ const taskLogger = { // jshint ignore:line
118
+ on : sinon . spy ( ) ,
119
+ restore : sinon . spy ( ( ) => Q . resolve ( ) ) ,
120
+ startHealthCheck : sinon . spy ( ) ,
121
+ onHealthCheckReported : onHealthCheckReportedSpy ,
122
+ } ;
123
+ const TaskLoggerFactory = sinon . spy ( ( ) => {
124
+ return Q . resolve ( taskLogger ) ;
125
+ } ) ;
126
+
127
+ const Logger = proxyquire ( '../lib/logger' , {
128
+ '@codefresh-io/task-logger' : { TaskLogger : TaskLoggerFactory }
129
+ } ) ;
130
+
131
+ const loggerId = 'loggerId' ;
132
+ const taskLoggerConfig = { task : { } , opts : { } } ;
133
+ const findExistingContainers = false ;
134
+
135
+ const logger = new Logger ( {
136
+ loggerId,
137
+ taskLoggerConfig,
138
+ findExistingContainers,
139
+ } ) ;
140
+ logger . _listenForNewContainers = sinon . spy ( ) ;
141
+ logger . _writeNewState = sinon . spy ( ) ;
142
+ logger . _listenForExistingContainers = sinon . spy ( ) ;
143
+ logger . start ( ) ;
144
+
145
+
146
+ await Q . delay ( 10 ) ;
147
+ onHealthCheckReportedCb ( { status : 'failed' } ) ;
148
+
149
+ expect ( taskLogger . startHealthCheck ) . to . be . calledOnce ;
150
+ expect ( logger . state . failedHealthChecks . length ) . to . be . equals ( 1 ) ;
151
+
152
+ } ) ;
153
+
154
+ it ( 'should report health check status if succeed' , async ( ) => { // jshint ignore:line
155
+ let onHealthCheckReportedCb ;
156
+ const onHealthCheckReportedSpy = sinon . spy ( ( func ) => {
157
+ onHealthCheckReportedCb = func ;
158
+ } ) ;
159
+
160
+ const taskLogger = { // jshint ignore:line
161
+ on : sinon . spy ( ) ,
162
+ restore : sinon . spy ( ( ) => Q . resolve ( ) ) ,
163
+ startHealthCheck : sinon . spy ( ) ,
164
+ onHealthCheckReported : onHealthCheckReportedSpy ,
165
+ } ;
166
+ const TaskLoggerFactory = sinon . spy ( ( ) => {
167
+ return Q . resolve ( taskLogger ) ;
168
+ } ) ;
169
+
170
+ const Logger = proxyquire ( '../lib/logger' , {
171
+ '@codefresh-io/task-logger' : { TaskLogger : TaskLoggerFactory }
172
+ } ) ;
173
+
174
+ const loggerId = 'loggerId' ;
175
+ const taskLoggerConfig = { task : { } , opts : { } } ;
176
+ const findExistingContainers = false ;
177
+
178
+ const logger = new Logger ( {
179
+ loggerId,
180
+ taskLoggerConfig,
181
+ findExistingContainers,
182
+ } ) ;
183
+ logger . _listenForNewContainers = sinon . spy ( ) ;
184
+ logger . _writeNewState = sinon . spy ( ) ;
185
+ logger . _listenForExistingContainers = sinon . spy ( ) ;
186
+ logger . start ( ) ;
187
+
188
+
189
+ await Q . delay ( 10 ) ;
190
+ onHealthCheckReportedCb ( { status : 'succeed' } ) ;
191
+
192
+ expect ( taskLogger . startHealthCheck ) . to . be . calledOnce ;
193
+ expect ( logger . state . healthCheckStatus ) . to . deep . equal ( { status : 'succeed' } ) ;
194
+
195
+ } ) ;
196
+
109
197
it ( 'should start and listen for existing container in case findExistingContainers param is "true"' , async ( ) => {
110
198
111
199
const taskLogger = {
112
200
on : sinon . spy ( ) ,
113
- restore : sinon . spy ( ( ) => Q . resolve ( ) )
201
+ restore : sinon . spy ( ( ) => Q . resolve ( ) ) ,
202
+ startHealthCheck : sinon . spy ( ) ,
203
+ onHealthCheckReported : sinon . spy ( ) ,
114
204
} ;
115
205
const TaskLoggerFactory = sinon . spy ( ( ) => {
116
206
return Q . resolve ( taskLogger ) ;
0 commit comments