Skip to content

Commit

Permalink
Port TestScheduledSuiteTimeoutFail to parallel test module
Browse files Browse the repository at this point in the history
  • Loading branch information
rhmdnd committed Apr 8, 2023
1 parent 2374f73 commit ffd0ecd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 65 deletions.
65 changes: 0 additions & 65 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1417,70 +1417,5 @@ func TestE2E(t *testing.T) {
return nil
},
},

testExecution{
Name: "TestScheduledSuiteTimeoutFail",
IsParallel: true,
TestFn: func(t *testing.T, f *framework.Framework, ctx *framework.Context, namespace string) error {
suiteName := "test-scheduled-suite-timeout-fail"

workerScanName := fmt.Sprintf("%s-workers-scan", suiteName)
selectWorkers := map[string]string{
"node-role.kubernetes.io/worker": "",
}

testSuite := &compv1alpha1.ComplianceSuite{
ObjectMeta: metav1.ObjectMeta{
Name: suiteName,
Namespace: namespace,
},
Spec: compv1alpha1.ComplianceSuiteSpec{
ComplianceSuiteSettings: compv1alpha1.ComplianceSuiteSettings{
AutoApplyRemediations: false,
},
Scans: []compv1alpha1.ComplianceScanSpecWrapper{
{
Name: workerScanName,
ComplianceScanSpec: compv1alpha1.ComplianceScanSpec{
ContentImage: contentImagePath,
Profile: "xccdf_org.ssgproject.content_profile_moderate",
Content: rhcosContentFile,
Rule: "xccdf_org.ssgproject.content_rule_no_netrc_files",
NodeSelector: selectWorkers,
ComplianceScanSettings: compv1alpha1.ComplianceScanSettings{
MaxRetryOnTimeout: 0,
RawResultStorage: compv1alpha1.RawResultStorageSettings{
Rotation: 1,
},
Timeout: "1s",
Debug: true,
},
},
},
},
},
}

err := f.Client.Create(goctx.TODO(), testSuite, getCleanupOpts(ctx))
if err != nil {
return err
}

// Ensure that all the scans in the suite have finished and are marked as Done
err = waitForSuiteScansStatus(t, f, namespace, suiteName, compv1alpha1.PhaseDone, compv1alpha1.ResultError)
if err != nil {
return err
}
scan := &compv1alpha1.ComplianceScan{}
err = f.Client.Get(goctx.TODO(), types.NamespacedName{Name: workerScanName, Namespace: namespace}, scan)
if err != nil {
return err
}
if _, ok := scan.Annotations[compv1alpha1.ComplianceScanTimeoutAnnotation]; !ok {
return fmt.Errorf("The scan should have the timeout annotation")
}
return nil
},
},
)
}
63 changes: 63 additions & 0 deletions tests/e2e/parallel/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2732,3 +2732,66 @@ func TestHideRule(t *testing.T) {
t.Fatalf("The check should not be found in the scan %s", scanName)
}
}

func TestScheduledSuiteTimeoutFail(t *testing.T) {
t.Parallel()
f := framework.Global
suiteName := "test-scheduled-suite-timeout-fail"

workerScanName := fmt.Sprintf("%s-workers-scan", suiteName)
selectWorkers := map[string]string{
"node-role.kubernetes.io/worker": "",
}

testSuite := &compv1alpha1.ComplianceSuite{
ObjectMeta: metav1.ObjectMeta{
Name: suiteName,
Namespace: f.OperatorNamespace,
},
Spec: compv1alpha1.ComplianceSuiteSpec{
ComplianceSuiteSettings: compv1alpha1.ComplianceSuiteSettings{
AutoApplyRemediations: false,
},
Scans: []compv1alpha1.ComplianceScanSpecWrapper{
{
Name: workerScanName,
ComplianceScanSpec: compv1alpha1.ComplianceScanSpec{
ContentImage: contentImagePath,
Profile: "xccdf_org.ssgproject.content_profile_moderate",
Content: framework.RhcosContentFile,
Rule: "xccdf_org.ssgproject.content_rule_no_netrc_files",
NodeSelector: selectWorkers,
ComplianceScanSettings: compv1alpha1.ComplianceScanSettings{
MaxRetryOnTimeout: 0,
RawResultStorage: compv1alpha1.RawResultStorageSettings{
Rotation: 1,
},
Timeout: "1s",
Debug: true,
},
},
},
},
},
}

err := f.Client.Create(context.TODO(), testSuite, nil)
if err != nil {
t.Fatal(err)
}
defer f.Client.Delete(context.TODO(), testSuite)

// Ensure that all the scans in the suite have finished and are marked as Done
err = f.WaitForSuiteScansStatus(f.OperatorNamespace, suiteName, compv1alpha1.PhaseDone, compv1alpha1.ResultError)
if err != nil {
t.Fatal(err)
}
scan := &compv1alpha1.ComplianceScan{}
err = f.Client.Get(context.TODO(), types.NamespacedName{Name: workerScanName, Namespace: f.OperatorNamespace}, scan)
if err != nil {
t.Fatal(err)
}
if _, ok := scan.Annotations[compv1alpha1.ComplianceScanTimeoutAnnotation]; !ok {
t.Fatal("The scan should have the timeout annotation")
}
}

0 comments on commit ffd0ecd

Please sign in to comment.