Skip to content

Commit

Permalink
chore: fix flaky e2e test for immutable fields (#11685)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
  • Loading branch information
crenshaw-dev committed Dec 13, 2022
1 parent 3c8c8ad commit 0f99cdd
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package e2e
import (
"context"
"fmt"
"math/rand"
"path"
"reflect"
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -370,23 +368,18 @@ func TestDeleteAppResource(t *testing.T) {
// demonstrate that we cannot use a standard sync when an immutable field is changed, we must use "force"
func TestImmutableChange(t *testing.T) {
SkipOnEnv(t, "OPENSHIFT")
text := FailOnErr(Run(".", "kubectl", "get", "service", "-n", "kube-system", "kube-dns", "-o", "jsonpath={.spec.clusterIP}")).(string)
parts := strings.Split(text, ".")
n := rand.Intn(254)
ip1 := fmt.Sprintf("%s.%s.%s.%d", parts[0], parts[1], parts[2], n)
ip2 := fmt.Sprintf("%s.%s.%s.%d", parts[0], parts[1], parts[2], n+1)
Given(t).
Path("service").
Path("secrets").
When().
CreateApp().
PatchFile("service.yaml", fmt.Sprintf(`[{"op": "add", "path": "/spec/clusterIP", "value": "%s"}]`, ip1)).
PatchFile("secrets.yaml", `[{"op": "add", "path": "/data/new-field", "value": "dGVzdA=="}, {"op": "add", "path": "/immutable", "value": true}]`).
Sync().
Then().
Expect(OperationPhaseIs(OperationSucceeded)).
Expect(SyncStatusIs(SyncStatusCodeSynced)).
Expect(HealthIs(health.HealthStatusHealthy)).
When().
PatchFile("service.yaml", fmt.Sprintf(`[{"op": "add", "path": "/spec/clusterIP", "value": "%s"}]`, ip2)).
PatchFile("secrets.yaml", `[{"op": "add", "path": "/data/new-field", "value": "dGVzdDI="}]`).
IgnoreErrors().
Sync().
DoNotIgnoreErrors().
Expand All @@ -395,14 +388,14 @@ func TestImmutableChange(t *testing.T) {
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
Expect(ResourceResultNumbering(1)).
Expect(ResourceResultMatches(ResourceResult{
Kind: "Service",
Kind: "Secret",
Version: "v1",
Namespace: DeploymentNamespace(),
Name: "my-service",
Name: "test-secret",
SyncPhase: "Sync",
Status: "SyncFailed",
HookPhase: "Failed",
Message: `Service "my-service" is invalid`,
Message: `Secret "test-secret" is invalid`,
})).
// now we can do this will a force
Given().
Expand Down

0 comments on commit 0f99cdd

Please sign in to comment.