@@ -19,6 +19,9 @@ import (
1919var (
2020 // defaultClusterInstanceCondition is a variable which depicts default value of ClusterInstance condition types.
2121 defaultClusterInstanceCondition = metav1.Condition {Type : "" , Status : metav1 .ConditionTrue }
22+
23+ // defaultClusterInstanceReinstallCondition depicts default value of ClusterInstanceReinstall condition types.
24+ defaultClusterInstanceReinstallCondition = metav1.Condition {Type : "" , Status : metav1 .ConditionTrue }
2225)
2326
2427const (
@@ -592,6 +595,79 @@ func TestClusterInstanceWaitForCondition(t *testing.T) {
592595 }
593596}
594597
598+ func TestClusterInstanceWaitForReinstallCondition (t * testing.T ) {
599+ testCases := []struct {
600+ condition metav1.Condition
601+ exists bool
602+ conditionMet bool
603+ valid bool
604+ expectedError error
605+ }{
606+ {
607+ condition : defaultClusterInstanceReinstallCondition ,
608+ exists : true ,
609+ conditionMet : true ,
610+ valid : true ,
611+ expectedError : nil ,
612+ },
613+ {
614+ condition : defaultClusterInstanceReinstallCondition ,
615+ exists : false ,
616+ conditionMet : true ,
617+ valid : true ,
618+ expectedError : fmt .Errorf ("clusterinstance object %s does not exist in namespace %s" ,
619+ testClusterInstance , testClusterInstance ),
620+ },
621+ {
622+ condition : defaultClusterInstanceReinstallCondition ,
623+ exists : true ,
624+ conditionMet : false ,
625+ valid : true ,
626+ expectedError : context .DeadlineExceeded ,
627+ },
628+ {
629+ condition : defaultClusterInstanceReinstallCondition ,
630+ exists : true ,
631+ conditionMet : true ,
632+ valid : false ,
633+ expectedError : fmt .Errorf ("clusterinstance 'nsname' cannot be empty" ),
634+ },
635+ }
636+
637+ for _ , testCase := range testCases {
638+ var (
639+ runtimeObjects []runtime.Object
640+ clusterInstanceBuilder * CIBuilder
641+ )
642+
643+ if testCase .exists {
644+ clusterinstance := generateClusterInstance ()
645+
646+ if testCase .conditionMet {
647+ clusterinstance .Status .Reinstall = & siteconfigv1alpha1.ReinstallStatus {}
648+ clusterinstance .Status .Reinstall .Conditions = append (clusterinstance .Status .Reinstall .Conditions ,
649+ testCase .condition )
650+ }
651+
652+ runtimeObjects = append (runtimeObjects , clusterinstance )
653+ }
654+
655+ testSettings := clients .GetTestClients (clients.TestClientParams {
656+ K8sMockObjects : runtimeObjects ,
657+ SchemeAttachers : testSchemes ,
658+ })
659+
660+ if testCase .valid {
661+ clusterInstanceBuilder = buildValidClusterInstanceTestBuilder (testSettings )
662+ } else {
663+ clusterInstanceBuilder = buildInvalidClusterInstanceTestBuilder (testSettings )
664+ }
665+
666+ _ , err := clusterInstanceBuilder .WaitForReinstallCondition (testCase .condition , time .Second )
667+ assert .Equal (t , testCase .expectedError , err )
668+ }
669+ }
670+
595671func TestClusterInstanceWaitForExtraLabel (t * testing.T ) {
596672 testCases := []struct {
597673 exists bool
0 commit comments