@@ -1437,6 +1437,70 @@ func newInvalidSpecCondition(reason string, resourceObj runtime.Object, optional
1437
1437
return condition , string (conditionBytes )
1438
1438
}
1439
1439
1440
+ func TestGetReferencedAnalyses (t * testing.T ) {
1441
+ f := newFixture (t )
1442
+ defer f .Close ()
1443
+
1444
+ rolloutAnalysisFail := v1alpha1.RolloutAnalysis {
1445
+ Templates : []v1alpha1.RolloutAnalysisTemplate {{
1446
+ TemplateName : "does-not-exist" ,
1447
+ ClusterScope : false ,
1448
+ }},
1449
+ }
1450
+
1451
+ t .Run ("blueGreen pre-promotion analysis - fail" , func (t * testing.T ) {
1452
+ r := newBlueGreenRollout ("rollout" , 1 , nil , "active-service" , "preview-service" )
1453
+ r .Spec .Strategy .BlueGreen .PrePromotionAnalysis = & rolloutAnalysisFail
1454
+ c , _ , _ := f .newController (noResyncPeriodFunc )
1455
+ roCtx , err := c .newRolloutContext (r )
1456
+ assert .NoError (t , err )
1457
+ _ , err = roCtx .getReferencedRolloutAnalyses ()
1458
+ assert .NotNil (t , err )
1459
+ msg := "spec.strategy.blueGreen.prePromotionAnalysis.templates: Invalid value: \" does-not-exist\" : AnalysisTemplate 'does-not-exist' not found"
1460
+ assert .Equal (t , msg , err .Error ())
1461
+ })
1462
+
1463
+ t .Run ("blueGreen post-promotion analysis - fail" , func (t * testing.T ) {
1464
+ r := newBlueGreenRollout ("rollout" , 1 , nil , "active-service" , "preview-service" )
1465
+ r .Spec .Strategy .BlueGreen .PostPromotionAnalysis = & rolloutAnalysisFail
1466
+ c , _ , _ := f .newController (noResyncPeriodFunc )
1467
+ roCtx , err := c .newRolloutContext (r )
1468
+ assert .NoError (t , err )
1469
+ _ , err = roCtx .getReferencedRolloutAnalyses ()
1470
+ assert .NotNil (t , err )
1471
+ msg := "spec.strategy.blueGreen.postPromotionAnalysis.templates: Invalid value: \" does-not-exist\" : AnalysisTemplate 'does-not-exist' not found"
1472
+ assert .Equal (t , msg , err .Error ())
1473
+ })
1474
+
1475
+ t .Run ("canary analysis - fail" , func (t * testing.T ) {
1476
+ r := newCanaryRollout ("rollout-canary" , 1 , nil , nil , int32Ptr (0 ), intstr .FromInt (0 ), intstr .FromInt (1 ))
1477
+ r .Spec .Strategy .Canary .Analysis = & v1alpha1.RolloutAnalysisBackground {
1478
+ RolloutAnalysis : rolloutAnalysisFail ,
1479
+ }
1480
+ c , _ , _ := f .newController (noResyncPeriodFunc )
1481
+ roCtx , err := c .newRolloutContext (r )
1482
+ assert .NoError (t , err )
1483
+ _ , err = roCtx .getReferencedRolloutAnalyses ()
1484
+ assert .NotNil (t , err )
1485
+ msg := "spec.strategy.canary.analysis.templates: Invalid value: \" does-not-exist\" : AnalysisTemplate 'does-not-exist' not found"
1486
+ assert .Equal (t , msg , err .Error ())
1487
+ })
1488
+
1489
+ t .Run ("canary step analysis - fail" , func (t * testing.T ) {
1490
+ canarySteps := []v1alpha1.CanaryStep {{
1491
+ Analysis : & rolloutAnalysisFail ,
1492
+ }}
1493
+ r := newCanaryRollout ("rollout-canary" , 1 , nil , canarySteps , int32Ptr (0 ), intstr .FromInt (0 ), intstr .FromInt (1 ))
1494
+ c , _ , _ := f .newController (noResyncPeriodFunc )
1495
+ roCtx , err := c .newRolloutContext (r )
1496
+ assert .NoError (t , err )
1497
+ _ , err = roCtx .getReferencedRolloutAnalyses ()
1498
+ assert .NotNil (t , err )
1499
+ msg := "spec.strategy.canary.steps[0].analysis.templates: Invalid value: \" does-not-exist\" : AnalysisTemplate 'does-not-exist' not found"
1500
+ assert .Equal (t , msg , err .Error ())
1501
+ })
1502
+ }
1503
+
1440
1504
func TestGetReferencedAnalysisTemplate (t * testing.T ) {
1441
1505
f := newFixture (t )
1442
1506
defer f .Close ()
@@ -1447,7 +1511,6 @@ func TestGetReferencedAnalysisTemplate(t *testing.T) {
1447
1511
ClusterScope : true ,
1448
1512
}},
1449
1513
}
1450
- defer f .Close ()
1451
1514
1452
1515
t .Run ("get referenced analysisTemplate - fail" , func (t * testing.T ) {
1453
1516
c , _ , _ := f .newController (noResyncPeriodFunc )
0 commit comments