@@ -1361,6 +1361,72 @@ func TestValidateExistingCRs(t *testing.T) {
1361
1361
}
1362
1362
}
1363
1363
1364
+ func TestSyncOperatorGroup (t * testing.T ) {
1365
+ namespace := "ns"
1366
+ inOperatorGroup := operatorGroup ("og" , "sa" , namespace ,
1367
+ & corev1.ObjectReference {
1368
+ Kind : "ServiceAccount" ,
1369
+ Namespace : namespace ,
1370
+ Name : "sa" ,
1371
+ })
1372
+ tests := []struct {
1373
+ testName string
1374
+ err error
1375
+ in * operatorsv1.OperatorGroup
1376
+ expectedPhase v1alpha1.InstallPlanPhase
1377
+ expectedCondition * v1alpha1.InstallPlanCondition
1378
+ clientObjs []runtime.Object
1379
+ }{
1380
+ {
1381
+ testName : "OnComplete" ,
1382
+ in : inOperatorGroup ,
1383
+ clientObjs : []runtime.Object {
1384
+ installPlan ("p" , namespace , v1alpha1 .InstallPlanPhaseComplete , "csv" ),
1385
+ },
1386
+ err : nil ,
1387
+ expectedPhase : v1alpha1 .InstallPlanPhaseInstalling ,
1388
+ expectedCondition : & v1alpha1.InstallPlanCondition {Type : v1alpha1 .InstallPlanInstalled , Status : corev1 .ConditionFalse , Reason : v1alpha1 .InstallPlanReasonComponentFailed ,
1389
+ Message : "OperatorGroup updated" },
1390
+ },
1391
+ {
1392
+ testName : "OnOnstalling" ,
1393
+ in : inOperatorGroup ,
1394
+ clientObjs : []runtime.Object {
1395
+ installPlan ("p" , namespace , v1alpha1 .InstallPlanPhaseNone , "csv" ),
1396
+ },
1397
+ err : nil ,
1398
+ expectedPhase : v1alpha1 .InstallPlanPhaseInstalling ,
1399
+ expectedCondition : & v1alpha1.InstallPlanCondition {Type : v1alpha1 .InstallPlanInstalled , Status : corev1 .ConditionFalse , Reason : v1alpha1 .InstallPlanReasonComponentFailed ,
1400
+ Message : "OperatorGroup updated" },
1401
+ },
1402
+ }
1403
+
1404
+ for _ , tt := range tests {
1405
+ t .Run (tt .testName , func (t * testing.T ) {
1406
+ ctx , cancel := context .WithCancel (context .TODO ())
1407
+ defer cancel ()
1408
+
1409
+ tt .clientObjs = append (tt .clientObjs , tt .in )
1410
+
1411
+ op , err := NewFakeOperator (ctx , namespace , []string {namespace }, withClientObjs (tt .clientObjs ... ))
1412
+ require .NoError (t , err )
1413
+
1414
+ err = op .syncOperatorGroup (tt .in )
1415
+ require .Equal (t , tt .err , err )
1416
+
1417
+ ip , err := op .client .OperatorsV1alpha1 ().InstallPlans (namespace ).Get (ctx , "p" , metav1.GetOptions {})
1418
+ require .NoError (t , err )
1419
+
1420
+ require .Equal (t , tt .expectedPhase , ip .Status .Phase )
1421
+
1422
+ if tt .expectedCondition != nil {
1423
+ require .True (t , hasExpectedCondition (ip , * tt .expectedCondition ))
1424
+ }
1425
+
1426
+ })
1427
+ }
1428
+ }
1429
+
1364
1430
func fakeConfigMapData () map [string ]string {
1365
1431
data := make (map [string ]string )
1366
1432
yaml , err := yaml .Marshal ([]apiextensionsv1beta1.CustomResourceDefinition {crd ("fake-crd" )})
0 commit comments