Skip to content

Commit

Permalink
Make the case23 test more reliable
Browse files Browse the repository at this point in the history
With a recent change of a noncompliant message being set that states the
object wasn't found before the object is attempted to be created, the test
would sometimes fail if it compared to the first noncompliant message.

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
  • Loading branch information
mprahl authored and openshift-merge-robot committed Feb 4, 2023
1 parent 82a7f86 commit 3f97c64
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions test/e2e/case23_invalid_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,18 @@ var _ = Describe("Test an objectDefinition with an invalid field", Ordered, func
By("Creating the " + policyName + " policy")
utils.Kubectl("apply", "-f", policyYAML, "-n", testNamespace)

By("Verifying that the " + policyName + " policy is noncompliant")
var managedPlc *unstructured.Unstructured
expectedMsg := "configmaps [case23] in namespace default is missing, and cannot be created, reason: " +
"`ValidationError(ConfigMap): unknown field \"invalid\" in io.k8s.api.core.v1.ConfigMap`"

Eventually(func() interface{} {
managedPlc = utils.GetWithTimeout(
By("Verifying that the " + policyName + " policy is noncompliant")
Eventually(func(g Gomega) {
managedPlc := utils.GetWithTimeout(
clientManagedDynamic, gvrConfigPolicy, policyName, testNamespace, true, defaultTimeoutSeconds,
)

return utils.GetComplianceState(managedPlc)
}, defaultTimeoutSeconds, 1).Should(Equal("NonCompliant"))

// expectedMsg := "Error validating the object case23, the error is `ValidationError(ConfigMap): unknown " +
// "field \"invalid\" in io.k8s.api.core.v1.ConfigMap`"
expectedMsg := "configmaps [case23] in namespace default is missing, and cannot be created, reason: " +
"`ValidationError(ConfigMap): unknown field \"invalid\" in io.k8s.api.core.v1.ConfigMap`"
Expect(utils.GetStatusMessage(managedPlc)).To(Equal(expectedMsg))
g.Expect(utils.GetComplianceState(managedPlc)).To(Equal("NonCompliant"))
g.Expect(utils.GetStatusMessage(managedPlc)).To(Equal(expectedMsg))
}, defaultTimeoutSeconds, 1).Should(Succeed())

By("Verifying the message is correct when the " + configMapName + " ConfigMap already exists")
configmap := &corev1.ConfigMap{
Expand All @@ -55,7 +51,7 @@ var _ = Describe("Test an objectDefinition with an invalid field", Ordered, func
expectedMsg = "Error validating the object case23, the error is `ValidationError(ConfigMap): unknown " +
"field \"invalid\" in io.k8s.api.core.v1.ConfigMap`"
Eventually(func() interface{} {
managedPlc = utils.GetWithTimeout(
managedPlc := utils.GetWithTimeout(
clientManagedDynamic, gvrConfigPolicy, policyName, testNamespace, true, defaultTimeoutSeconds,
)

Expand Down

0 comments on commit 3f97c64

Please sign in to comment.