@@ -230,122 +230,82 @@ func TestGetDeployments(t *testing.T) {
230
230
}
231
231
}
232
232
233
- func TestGetDeployStatus (t * testing.T ) {
233
+ func TestExitErrorMessage (t * testing.T ) {
234
234
tests := []struct {
235
235
description string
236
236
counter * counter
237
- deployments []* resource.Resource
238
- ctxErr error
237
+ sc proto.StatusCode
239
238
expected string
240
239
expectedCode proto.StatusCode
241
240
shouldErr bool
242
241
}{
243
242
{
244
- description : "one error" ,
245
- counter : & counter {total : 2 , failed : 1 },
246
- deployments : []* resource.Resource {
247
- resource .NewResource ("foo" , resource .ResourceTypes .Deployment , "test" , time .Second ).
248
- WithPodStatuses ([]proto.StatusCode {proto .StatusCode_STATUSCHECK_NODE_DISK_PRESSURE }),
249
- },
243
+ description : "one error" ,
244
+ counter : & counter {total : 2 , failed : 1 },
250
245
expected : "1/2 deployment(s) failed" ,
251
- expectedCode : proto .StatusCode_STATUSCHECK_NODE_DISK_PRESSURE ,
246
+ sc : proto .StatusCode_STATUSCHECK_POD_INITIALIZING ,
247
+ expectedCode : proto .StatusCode_STATUSCHECK_POD_INITIALIZING ,
252
248
shouldErr : true ,
253
249
},
254
250
{
255
- description : "no error" ,
256
- counter : & counter {total : 2 },
257
- deployments : []* resource.Resource {
258
- withStatus (
259
- resource .NewResource ("r1" , resource .ResourceTypes .Deployment , "test" , 1 ),
260
- & proto.ActionableErr {ErrCode : proto .StatusCode_STATUSCHECK_SUCCESS },
261
- ),
262
- withStatus (
263
- resource .NewResource ("r2" , resource .ResourceTypes .Deployment , "test" , 1 ),
264
- & proto.ActionableErr {ErrCode : proto .StatusCode_STATUSCHECK_SUCCESS },
265
- ),
266
- },
251
+ description : "no error" ,
252
+ sc : proto .StatusCode_STATUSCHECK_SUCCESS ,
253
+ expectedCode : proto .StatusCode_STATUSCHECK_SUCCESS ,
254
+ counter : & counter {total : 2 },
267
255
},
268
256
{
269
- description : "multiple errors" ,
270
- counter : & counter {total : 3 , failed : 2 },
271
- expected : "2/3 deployment(s) failed" ,
272
- deployments : []* resource.Resource {
273
- resource .NewResource ("foo" , resource .ResourceTypes .Deployment , "test" , time .Second ).
274
- WithPodStatuses ([]proto.StatusCode {proto .StatusCode_STATUSCHECK_NODE_DISK_PRESSURE }),
275
- },
276
- expectedCode : proto .StatusCode_STATUSCHECK_NODE_DISK_PRESSURE ,
257
+ description : "multiple errors" ,
258
+ counter : & counter {total : 3 , failed : 2 },
259
+ expected : "2/3 deployment(s) failed" ,
260
+ sc : proto .StatusCode_STATUSCHECK_CONFIG_CONNECTOR_FAILED ,
261
+ expectedCode : proto .StatusCode_STATUSCHECK_CONFIG_CONNECTOR_FAILED ,
277
262
shouldErr : true ,
278
263
},
279
264
{
280
265
description : "0 deployments" ,
281
- counter : & counter {},
266
+ counter : & counter {total : 0 },
267
+ expectedCode : proto .StatusCode_STATUSCHECK_SUCCESS ,
282
268
},
283
269
{
284
- description : "unable to retrieve pods for deployment" ,
285
- counter : & counter {total : 1 , failed : 1 },
286
- deployments : []* resource.Resource {
287
- withStatus (
288
- resource .NewResource ("deployment" , resource .ResourceTypes .Deployment , "test" , 1 ),
289
- & proto.ActionableErr {ErrCode : proto .StatusCode_STATUSCHECK_DEPLOYMENT_FETCH_ERR },
290
- ),
291
- },
292
- shouldErr : true ,
270
+ description : "unable to retrieve pods for deployment" ,
271
+ counter : & counter {total : 1 , failed : 1 },
272
+ sc : proto .StatusCode_STATUSCHECK_DEPLOYMENT_FETCH_ERR ,
293
273
expectedCode : proto .StatusCode_STATUSCHECK_DEPLOYMENT_FETCH_ERR ,
274
+ shouldErr : true ,
294
275
},
295
276
{
296
- description : "one deployment failed and others cancelled and or succeeded" ,
297
- counter : & counter {total : 3 , failed : 2 },
298
- deployments : []* resource.Resource {
299
- withStatus (
300
- resource .NewResource ("deployment-cancelled" , resource .ResourceTypes .Deployment , "test" , 1 ),
301
- & proto.ActionableErr {ErrCode : proto .StatusCode_STATUSCHECK_USER_CANCELLED },
302
- ),
303
- withStatus (
304
- resource .NewResource ("deployment-success" , resource .ResourceTypes .Deployment , "test" , 1 ),
305
- & proto.ActionableErr {ErrCode : proto .StatusCode_STATUSCHECK_SUCCESS },
306
- ),
307
- withStatus (
308
- resource .NewResource ("deployment" , resource .ResourceTypes .Deployment , "test" , 1 ),
309
- & proto.ActionableErr {ErrCode : proto .StatusCode_STATUSCHECK_DEPLOYMENT_FETCH_ERR },
310
- ),
311
- },
277
+ description : "one deployment failed and others cancelled and or succeeded" ,
278
+ counter : & counter {total : 3 , failed : 2 },
279
+ sc : proto .StatusCode_STATUSCHECK_NODE_DISK_PRESSURE ,
280
+ expectedCode : proto .StatusCode_STATUSCHECK_NODE_DISK_PRESSURE ,
281
+ expected : "2/3 deployment(s) failed" ,
312
282
shouldErr : true ,
313
- expectedCode : proto .StatusCode_STATUSCHECK_DEPLOYMENT_FETCH_ERR ,
314
283
},
315
284
{
316
- description : "deployments did not stabilize within deadline" ,
317
- counter : & counter {total : 3 , failed : 2 },
318
- ctxErr : context .DeadlineExceeded ,
319
- expected : "2/3 deployment(s) failed" ,
320
- deployments : []* resource.Resource {
321
- resource .NewResource ("foo" , resource .ResourceTypes .Deployment , "test" , time .Second ).
322
- WithPodStatuses ([]proto.StatusCode {proto .StatusCode_STATUSCHECK_NODE_DISK_PRESSURE }),
323
- },
324
- expectedCode : proto .StatusCode_STATUSCHECK_DEADLINE_EXCEEDED ,
285
+ description : "deployments did not stabilize within deadline returns the pod error" ,
286
+ counter : & counter {total : 1 , failed : 1 },
287
+ sc : proto .StatusCode_STATUSCHECK_UNHEALTHY ,
288
+ expected : "1/1 deployment(s) failed" ,
289
+ expectedCode : proto .StatusCode_STATUSCHECK_UNHEALTHY ,
325
290
shouldErr : true ,
326
291
},
327
292
{
328
- description : "user cancelled session" ,
329
- counter : & counter {total : 1 , failed : 1 },
330
- ctxErr : context .Canceled ,
331
- expected : "1/1 deployment(s) failed" ,
332
- deployments : []* resource.Resource {
333
- resource .NewResource ("foo" , resource .ResourceTypes .Deployment , "test" , time .Second ).
334
- WithPodStatuses ([]proto.StatusCode {proto .StatusCode_STATUSCHECK_POD_INITIALIZING }),
335
- },
293
+ description : "user cancelled session" ,
294
+ counter : & counter {total : 2 , failed : 0 , cancelled : 2 },
295
+ sc : proto .StatusCode_STATUSCHECK_USER_CANCELLED ,
296
+ expected : "status check cancelled" ,
336
297
expectedCode : proto .StatusCode_STATUSCHECK_USER_CANCELLED ,
337
298
shouldErr : true ,
338
299
},
339
300
}
340
301
341
302
for _ , test := range tests {
342
303
testutil .Run (t , test .description , func (t * testutil.T ) {
343
- testEvent .InitializeState ([]latestV1.Pipeline {{}})
344
- errCode , err := getSkaffoldDeployStatus (test .counter , test .deployments , test .ctxErr )
304
+ actual , err := getSkaffoldDeployStatus (test .counter , test .sc )
345
305
t .CheckError (test .shouldErr , err )
306
+ t .CheckDeepEqual (test .expectedCode , actual )
346
307
if test .shouldErr {
347
308
t .CheckErrorContains (test .expected , err )
348
- t .CheckDeepEqual (test .expectedCode , errCode )
349
309
}
350
310
})
351
311
}
@@ -554,29 +514,37 @@ func TestResourceMarkProcessed(t *testing.T) {
554
514
tests := []struct {
555
515
description string
556
516
c * counter
557
- err error
517
+ sc proto. StatusCode
558
518
expected counter
559
519
}{
560
520
{
561
521
description : "when deployment failed, counter is updated" ,
562
522
c : newCounter (10 ),
563
- err : errors . New ( "some ae" ) ,
523
+ sc : proto . StatusCode_STATUSCHECK_DEADLINE_EXCEEDED ,
564
524
expected : counter {total : 10 , failed : 1 , pending : 9 },
565
525
},
526
+ {
527
+ description : "when deployment is cancelled, failed is not updated" ,
528
+ c : newCounter (10 ),
529
+ sc : proto .StatusCode_STATUSCHECK_USER_CANCELLED ,
530
+ expected : counter {total : 10 , failed : 0 , pending : 9 },
531
+ },
566
532
{
567
533
description : "when deployment is successful, counter is updated" ,
568
534
c : newCounter (10 ),
535
+ sc : proto .StatusCode_STATUSCHECK_SUCCESS ,
569
536
expected : counter {total : 10 , failed : 0 , pending : 9 },
570
537
},
571
538
{
572
539
description : "counter when 1 deployment is updated correctly" ,
573
540
c : newCounter (1 ),
541
+ sc : proto .StatusCode_STATUSCHECK_SUCCESS ,
574
542
expected : counter {total : 1 , failed : 0 , pending : 0 },
575
543
},
576
544
}
577
545
for _ , test := range tests {
578
546
testutil .Run (t , test .description , func (t * testutil.T ) {
579
- t .CheckDeepEqual (test .expected , test .c .markProcessed (test .err ), cmp .AllowUnexported (counter {}))
547
+ t .CheckDeepEqual (test .expected , test .c .markProcessed (context . Background (), test .sc ), cmp .AllowUnexported (counter {}))
580
548
})
581
549
}
582
550
}
0 commit comments