Skip to content

Commit

Permalink
Test node profile removal cleanup for SSB
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent056 committed Mar 22, 2024
1 parent da5b8f5 commit 219c377
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions tests/e2e/serial/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,11 @@ func TestRemoveProfileScan(t *testing.T) {
Kind: "Profile",
APIGroup: "compliance.openshift.io/v1alpha1",
},
{
Name: "ocp4-cis-node",
Kind: "Profile",
APIGroup: "compliance.openshift.io/v1alpha1",
},
},
SettingsRef: &compv1alpha1.NamedObjectReference{
Name: "default",
Expand All @@ -1565,6 +1570,14 @@ func TestRemoveProfileScan(t *testing.T) {
t.Fatal(err)
}

if err := f.AssertScanExists("ocp4-cis-node-master", f.OperatorNamespace); err != nil {
t.Fatal(err)
}

if err := f.AssertScanExists("ocp4-cis-node-worker", f.OperatorNamespace); err != nil {
t.Fatal(err)
}

scanName := "ocp4-moderate"
checkResult := compv1alpha1.ComplianceCheckResult{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1580,7 +1593,7 @@ func TestRemoveProfileScan(t *testing.T) {
t.Fatal(err)
}

// Remove the `ocp4-moderate` profile from the `ScanSettingBinding`
// Remove the `ocp4-moderate` and `ocp4-cis-node` profile from the `ScanSettingBinding`
scanSettingBindingUpdate := &compv1alpha1.ScanSettingBinding{}
if err := f.Client.Get(context.TODO(), types.NamespacedName{Namespace: f.OperatorNamespace, Name: bindingName}, scanSettingBindingUpdate); err != nil {
t.Fatalf("failed to get ScanSettingBinding %s", bindingName)
Expand All @@ -1596,10 +1609,17 @@ func TestRemoveProfileScan(t *testing.T) {
if err := f.Client.Update(context.TODO(), scanSettingBindingUpdate); err != nil {
t.Fatal(err)
}

var lastErr error
timeouterr := wait.Poll(framework.RetryInterval, framework.Timeout, func() (bool, error) {
if lastErr := f.AssertScanDoesNotExist(scanName, f.OperatorNamespace); lastErr != nil {
if lastErr := f.AssertScanDoesNotExist("ocp4-moderate", f.OperatorNamespace); lastErr != nil {
log.Printf("Retrying: %s\n", lastErr)
return false, nil
}
if lastErr := f.AssertScanDoesNotExist("ocp4-cis-node-master", f.OperatorNamespace); lastErr != nil {
log.Printf("Retrying: %s\n", lastErr)
return false, nil
}
if lastErr := f.AssertScanDoesNotExist("ocp4-cis-node-worker", f.OperatorNamespace); lastErr != nil {
log.Printf("Retrying: %s\n", lastErr)
return false, nil
}
Expand All @@ -1614,7 +1634,7 @@ func TestRemoveProfileScan(t *testing.T) {
}
return false, nil
}
log.Printf("Scan %s doesn't exist anymore\n", scanName)
log.Print("Scan ocp4-moderate, ocp4-cis-node-master and ocp4-cis-node-worker do not exist anymore\n")
log.Printf("Check %s doesn't exist anymore\n", checkResult.Name)
return true, nil
})
Expand All @@ -1626,7 +1646,6 @@ func TestRemoveProfileScan(t *testing.T) {
if timeouterr != nil {
t.Fatalf("timed out waiting for scan and check to be removed: %s", timeouterr)
}

}

func TestSuspendScanSettingDoesNotCreateScan(t *testing.T) {
Expand Down

0 comments on commit 219c377

Please sign in to comment.