Skip to content

Commit

Permalink
chore: Make e2e tests work on K8s v1.20 (argoproj#5491)
Browse files Browse the repository at this point in the history
* chore: Make e2e tests work on K8s v1.20

Signed-off-by: jannfis <jann@mistrust.net>

* Fix linter complaints

Signed-off-by: jannfis <jann@mistrust.net>
  • Loading branch information
jannfis authored Feb 11, 2021
1 parent 2985081 commit 2d06b50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ func TestImmutableChange(t *testing.T) {
Expect(OperationPhaseIs(OperationFailed)).
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
Expect(ResourceResultNumbering(1)).
Expect(ResourceResultIs(ResourceResult{
Expect(ResourceResultMatches(ResourceResult{
Kind: "Service",
Version: "v1",
Namespace: DeploymentNamespace(),
Name: "my-service",
SyncPhase: "Sync",
Status: "SyncFailed",
HookPhase: "Failed",
Message: fmt.Sprintf(`Service "my-service" is invalid: spec.clusterIP: Invalid value: "%s": field is immutable`, ip2),
Message: `Service "my-service" is invalid`,
})).
// now we can do this will a force
Given().
Expand Down
26 changes: 26 additions & 0 deletions test/e2e/fixture/app/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"context"
"fmt"
"regexp"
"strings"

"github.com/argoproj/gitops-engine/pkg/health"
Expand Down Expand Up @@ -142,6 +143,31 @@ func ResourceResultIs(result ResourceResult) Expectation {
}
}

func sameResourceResult(res1, res2 ResourceResult) bool {
return res1.Kind == res2.Kind &&
res1.Group == res2.Group &&
res1.Namespace == res2.Namespace &&
res1.Name == res2.Name &&
res1.SyncPhase == res2.SyncPhase &&
res1.Status == res2.Status &&
res1.HookPhase == res2.HookPhase
}

func ResourceResultMatches(result ResourceResult) Expectation {
return func(c *Consequences) (state, string) {
results := c.app().Status.OperationState.SyncResult.Resources
for _, res := range results {
if sameResourceResult(*res, result) {
re := regexp.MustCompile(result.Message)
if re.MatchString(res.Message) {
return succeeded, fmt.Sprintf("found resource result %v", result)
}
}
}
return pending, fmt.Sprintf("waiting for resource result %v in %v", result, results)
}
}

func DoesNotExist() Expectation {
return func(c *Consequences) (state, string) {
_, err := c.get()
Expand Down

0 comments on commit 2d06b50

Please sign in to comment.