@@ -37,6 +37,126 @@ func TestCalculateComplianceConditionShortCircuitOnInvalid(t *testing.T) {
3737 assert .NotContains (t , cond .Message , "the status of the OperatorGroup could not be determined" )
3838 assert .NotContains (t , cond .Message , "the status of the Subscription could not be determined" )
3939 assert .NotContains (t , cond .Message , "the status of the InstallPlan could not be determined" )
40+ assert .NotContains (t , cond .Message , "the OperatorGroup is compliant" )
41+ }
42+
43+ func TestShortCircuitOnMissingValidPolicySpec (t * testing.T ) {
44+ pol := & policyv1beta1.OperatorPolicy {}
45+
46+ cond := calculateComplianceCondition (pol )
47+
48+ assert .Equal (t , metav1 .ConditionFalse , cond .Status )
49+ assert .Equal (t , "NonCompliant; the validity of the policy is unknown" , cond .Message )
50+ }
51+
52+ func TestShortCircuitOnMissingOperatorGroup (t * testing.T ) {
53+ pol := & policyv1beta1.OperatorPolicy {}
54+ pol .Status .Conditions = []metav1.Condition {
55+ {
56+ Type : validPolicyConditionType ,
57+ Status : metav1 .ConditionTrue ,
58+ Reason : "PolicyValidated" ,
59+ Message : "the policy spec is valid" ,
60+ },
61+ }
62+
63+ cond := calculateComplianceCondition (pol )
64+
65+ assert .Equal (t , metav1 .ConditionFalse , cond .Status )
66+ assert .Equal (t , "NonCompliant; the status of the OperatorGroup is unknown" , cond .Message )
67+ }
68+
69+ func TestShortCircuitOnMissingSubscription (t * testing.T ) {
70+ pol := & policyv1beta1.OperatorPolicy {}
71+ pol .Status .Conditions = []metav1.Condition {
72+ {
73+ Type : validPolicyConditionType ,
74+ Status : metav1 .ConditionTrue ,
75+ Reason : "PolicyValidated" ,
76+ Message : "the policy spec is valid" ,
77+ },
78+ {
79+ Type : opGroupConditionType ,
80+ Status : metav1 .ConditionTrue ,
81+ Reason : "OperatorGroupCompliant" ,
82+ Message : "the OperatorGroup is compliant" ,
83+ },
84+ }
85+
86+ cond := calculateComplianceCondition (pol )
87+
88+ assert .Equal (t , metav1 .ConditionFalse , cond .Status )
89+ assert .Equal (t , "NonCompliant; the status of the Subscription is unknown" , cond .Message )
90+ }
91+
92+ func TestCalculateComplianceConditionAggregatesAllCompliant (t * testing.T ) {
93+ pol := & policyv1beta1.OperatorPolicy {}
94+ pol .Status .Conditions = []metav1.Condition {
95+ {
96+ Type : validPolicyConditionType ,
97+ Status : metav1 .ConditionTrue ,
98+ Reason : "PolicyValidated" ,
99+ Message : "the policy spec is valid" ,
100+ },
101+ {
102+ Type : opGroupConditionType ,
103+ Status : metav1 .ConditionTrue ,
104+ Reason : "OperatorGroupMatches" ,
105+ Message : "the OperatorGroup matches what is required by the policy" ,
106+ },
107+ {
108+ Type : subConditionType ,
109+ Status : metav1 .ConditionTrue ,
110+ Reason : "SubscriptionMatches" ,
111+ Message : "the Subscription matches what is required by the policy" ,
112+ },
113+ {
114+ Type : installPlanConditionType ,
115+ Status : metav1 .ConditionTrue ,
116+ Reason : "NoInstallPlansFound" ,
117+ Message : "there are no relevant InstallPlans in the namespace" ,
118+ },
119+ {
120+ Type : csvConditionType ,
121+ Status : metav1 .ConditionTrue ,
122+ Reason : "Succeeded" ,
123+ Message : "the ClusterServiceVersion is succeeded" ,
124+ },
125+ {
126+ Type : crdConditionType ,
127+ Status : metav1 .ConditionTrue ,
128+ Reason : "RelevantCRDFound" ,
129+ Message : "there are CRDs present for the operator" ,
130+ },
131+ {
132+ Type : deploymentConditionType ,
133+ Status : metav1 .ConditionTrue ,
134+ Reason : "DeploymentsAvailable" ,
135+ Message : "all operator Deployments have their minimum availability" ,
136+ },
137+ // CatalogSource polarity: False means healthy/non-blocking for compliance aggregation
138+ {
139+ Type : catalogSrcConditionType ,
140+ Status : metav1 .ConditionFalse ,
141+ Reason : "CatalogSourcesFound" ,
142+ Message : "CatalogSource was found" ,
143+ },
144+ }
145+
146+ cond := calculateComplianceCondition (pol )
147+
148+ expected := "Compliant; " +
149+ "the policy spec is valid, " +
150+ "the OperatorGroup matches what is required by the policy, " +
151+ "the Subscription matches what is required by the policy, " +
152+ "there are no relevant InstallPlans in the namespace, " +
153+ "the ClusterServiceVersion is succeeded, " +
154+ "there are CRDs present for the operator, " +
155+ "all operator Deployments have their minimum availability, " +
156+ "CatalogSource was found"
157+
158+ assert .Equal (t , metav1 .ConditionTrue , cond .Status )
159+ assert .Equal (t , expected , cond .Message )
40160}
41161
42162func TestExistingInstallPlanObj (t * testing.T ) {
0 commit comments