@@ -1762,6 +1762,44 @@ func CreateResultMap(_ *testConfig.TestConfig, c dynclient.Client, suiteName str
17621762 return resultMap , nil
17631763}
17641764
1765+ // CheckAutomatedRemediationPassed verifies that all ComplianceCheckResults with automated remediation
1766+ // are in PASS status. If any automated remediation results are not PASS, it returns an error.
1767+ func CheckAutomatedRemediationPassed (tc * testConfig.TestConfig , c dynclient.Client , suiteName string ) error {
1768+ labelSelectorStr := fmt .Sprintf ("%s,%s!=PASS,%s=%s" ,
1769+ cmpv1alpha1 .ComplianceCheckResultHasRemediation ,
1770+ cmpv1alpha1 .ComplianceCheckResultStatusLabel ,
1771+ cmpv1alpha1 .SuiteLabel ,
1772+ suiteName ,
1773+ )
1774+ labelSelector , err := labels .Parse (labelSelectorStr )
1775+ if err != nil {
1776+ return fmt .Errorf ("failed to parse label selector: %w" , err )
1777+ }
1778+
1779+ resultList := & cmpv1alpha1.ComplianceCheckResultList {}
1780+ opts := & dynclient.ListOptions {
1781+ LabelSelector : labelSelector ,
1782+ Namespace : tc .OperatorNamespace .Namespace ,
1783+ }
1784+ err = c .List (goctx .TODO (), resultList , opts )
1785+ if err != nil {
1786+ return fmt .Errorf ("failed to get compliance check results for suite %s: %w" , suiteName , err )
1787+ }
1788+
1789+ if len (resultList .Items ) > 0 {
1790+ var nonPassResults []string
1791+ for i := range resultList .Items {
1792+ result := & resultList .Items [i ]
1793+ nonPassResults = append (nonPassResults , fmt .Sprintf ("%s (status: %s)" , result .Name , result .Status ))
1794+ }
1795+ return fmt .Errorf ("found %d ComplianceCheckResult(s) with automated remediation that are not in PASS status for suite %s: %v" ,
1796+ len (resultList .Items ), suiteName , nonPassResults )
1797+ }
1798+
1799+ log .Printf ("All ComplianceCheckResults with automated remediation are in PASS status for suite %s" , suiteName )
1800+ return nil
1801+ }
1802+
17651803// SaveResultAsYAML saves YAML data about the scan results to a file in the configured log directory.
17661804func SaveResultAsYAML (tc * testConfig.TestConfig , results map [string ]string , filename string ) error {
17671805 p := path .Join (tc .LogDir , filename )
0 commit comments