@@ -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,78 @@ 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 .Conditions = append (clusterinstance .Status .Reinstall .Conditions ,
648+ testCase .condition )
649+ }
650+
651+ runtimeObjects = append (runtimeObjects , clusterinstance )
652+ }
653+
654+ testSettings := clients .GetTestClients (clients.TestClientParams {
655+ K8sMockObjects : runtimeObjects ,
656+ SchemeAttachers : testSchemes ,
657+ })
658+
659+ if testCase .valid {
660+ clusterInstanceBuilder = buildValidClusterInstanceTestBuilder (testSettings )
661+ } else {
662+ clusterInstanceBuilder = buildInvalidClusterInstanceTestBuilder (testSettings )
663+ }
664+
665+ _ , err := clusterInstanceBuilder .WaitForReinstallCondition (testCase .condition , time .Second )
666+ assert .Equal (t , testCase .expectedError , err )
667+ }
668+ }
669+
595670func TestClusterInstanceWaitForExtraLabel (t * testing.T ) {
596671 testCases := []struct {
597672 exists bool
0 commit comments