Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/e2e/framework/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,45 @@ func (f *Framework) GetConfigMapsFromScan(scaninstance *compv1alpha1.ComplianceS
return configmaps.Items, nil
}

// GetScanExitCodeAndErrorMsg retrieves the exit code and error message from a scan's ConfigMaps
// Returns exit code as a string, error message as a string, and an error if any occurred
// If no ConfigMaps exist or if exit-code/error-msg are not found, returns empty strings
func (f *Framework) GetScanExitCodeAndErrorMsg(scanName, namespace string) (string, string, error) {
// Get the scan
scan := &compv1alpha1.ComplianceScan{}
err := f.Client.Get(context.TODO(), types.NamespacedName{Name: scanName, Namespace: namespace}, scan)
if err != nil {
return "", "", fmt.Errorf("failed to get scan %s: %w", scanName, err)
}

// Get ConfigMaps from the scan
configMaps, err := f.GetConfigMapsFromScan(scan)
if err != nil {
return "", "", fmt.Errorf("failed to get ConfigMaps from scan %s: %w", scanName, err)
}

var exitCode string
var errorMsg string

// Look for exit-code in ConfigMaps
for _, cm := range configMaps {
if code, ok := cm.Data["exit-code"]; ok {
exitCode = code
break
}
}

// Look for error-msg in ConfigMaps
for _, cm := range configMaps {
if msg, ok := cm.Data["error-msg"]; ok {
errorMsg = msg
break
}
}

return exitCode, errorMsg, nil
}

func (f *Framework) GetPodsForScan(scanName string) ([]core.Pod, error) {
selectPods := map[string]string{
compv1alpha1.ComplianceScanLabel: scanName,
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/parallel/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,15 @@ func TestSingleScanSucceeds(t *testing.T) {
if err != nil {
t.Fatalf("failed to assert PVC reference for scan %s: %s", scanName, err)
}

// Validate exit-code is "0"
exitCode, _, err := f.GetScanExitCodeAndErrorMsg(scanName, f.OperatorNamespace)
if err != nil {
t.Fatal(err)
}
if exitCode != "0" {
t.Fatalf("Expected ConfigMap exit-code to be '0', but got: '%s'", exitCode)
}
}

func TestSingleScanTimestamps(t *testing.T) {
Expand Down Expand Up @@ -1064,6 +1073,15 @@ func TestScanWithUnexistentResourceFails(t *testing.T) {
if err = f.ScanHasWarnings(scanName, f.OperatorNamespace); err != nil {
t.Fatal(err)
}

// Validate exit-code is "2"
exitCode, _, err := f.GetScanExitCodeAndErrorMsg(scanName, f.OperatorNamespace)
if err != nil {
t.Fatal(err)
}
if exitCode != "2" {
t.Fatalf("Expected ConfigMap exit-code to be '2', but got: '%s'", exitCode)
}
}

func TestScanStorageOutOfLimitRangeFails(t *testing.T) {
Expand Down
Loading