Skip to content

Commit

Permalink
fix e2e
Browse files Browse the repository at this point in the history
Signed-off-by: clyang82 <chuyang@redhat.com>
  • Loading branch information
clyang82 committed May 29, 2023
1 parent 9a6bfd9 commit b6fba5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2621,6 +2621,12 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(
}

if err != nil {
if strings.Contains(err.Error(), "strict decoding error:") {
message := fmt.Sprintf("Error validating the object %s, the error is `%v`", obj.name, err)

return false, message, true, updateNeeded, false
}

message := fmt.Sprintf("Error updating the object `%v`, the error is `%v`", obj.name, err)

return false, message, true, updateNeeded, false
Expand Down
12 changes: 7 additions & 5 deletions test/e2e/case23_invalid_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ var _ = Describe("Test an objectDefinition with an invalid field", Ordered, func
utils.Kubectl("apply", "-f", policyYAML, "-n", testNamespace)

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`"
"`ConfigMap in version \"v1\" cannot be handled as a ConfigMap: strict decoding error: unknown " +
"field \"invalid\"`"

By("Verifying that the " + policyName + " policy is noncompliant")
Eventually(func(g Gomega) {
Expand All @@ -47,7 +48,8 @@ var _ = Describe("Test an objectDefinition with an invalid field", Ordered, func
compPlcEvents := utils.GetMatchingEvents(clientManaged, testNamespace,
policyName,
"",
"unknown field \"invalid\" in io.k8s.api.core.v1.ConfigMap",
"ConfigMap in version \"v1\" cannot be handled as a ConfigMap: "+
"strict decoding error: unknown field \"invalid\"",
defaultTimeoutSeconds)

if len(compPlcEvents) == 0 {
Expand All @@ -66,8 +68,8 @@ var _ = Describe("Test an objectDefinition with an invalid field", Ordered, func
_, err := clientManaged.CoreV1().ConfigMaps("default").Create(context.TODO(), configmap, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

expectedMsg = "Error validating the object case23, the error is `ValidationError(ConfigMap): unknown " +
"field \"invalid\" in io.k8s.api.core.v1.ConfigMap`"
expectedMsg = "Error validating the object case23, the error is `ConfigMap in version \"v1\"" +
" cannot be handled as a ConfigMap: strict decoding error: unknown field \"invalid\"`"
Eventually(func() interface{} {
managedPlc := utils.GetWithTimeout(
clientManagedDynamic, gvrConfigPolicy, policyName, testNamespace, true, defaultTimeoutSeconds,
Expand All @@ -83,7 +85,7 @@ var _ = Describe("Test an objectDefinition with an invalid field", Ordered, func
compPlcEvents := utils.GetMatchingEvents(clientManaged, testNamespace,
policyName,
"",
"unknown field \"invalid\" in io.k8s.api.core.v1.ConfigMap",
"strict decoding error: unknown field \"invalid\"",
defaultTimeoutSeconds)

if len(compPlcEvents) == 0 {
Expand Down

0 comments on commit b6fba5f

Please sign in to comment.