From e1def4f8ac11b9d73c1caaa13a7c69626c964315 Mon Sep 17 00:00:00 2001 From: Max Jonas Werner Date: Wed, 18 May 2022 16:36:18 +0200 Subject: [PATCH 1/3] make e2e test easier to debug Signed-off-by: Max Jonas Werner --- cmd/flux/check_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/flux/check_test.go b/cmd/flux/check_test.go index e6374535..41b885ab 100644 --- a/cmd/flux/check_test.go +++ b/cmd/flux/check_test.go @@ -37,7 +37,7 @@ func TestCheckPre(t *testing.T) { var versions map[string]version.Info if err := json.Unmarshal([]byte(jsonOutput), &versions); err != nil { - t.Fatalf("Error unmarshalling: %v", err.Error()) + t.Fatalf("Error unmarshalling '%s': %v", jsonOutput, err.Error()) } serverVersion := strings.TrimPrefix(versions["serverVersion"].GitVersion, "v") From 9af61753020bc8a55531a451365f1474b0bc213d Mon Sep 17 00:00:00 2001 From: Max Jonas Werner Date: Wed, 18 May 2022 16:51:18 +0200 Subject: [PATCH 2/3] fix e2e check test The output of `kubectl version` has changed with newer kubectl version from ``` { "serverVersion": ..., "clientVersion": ... } ``` to ``` { "serverVersion": ..., "clientVersion": ..., "kustomizeVersion": ... } ``` So the `kustomizeVersion` field is new which causes the JSON unmarshaling to fail. We now just unmarshal it to `map[string]interface{}` and peel the server git version out of that map manually w/o unmarshalling the JSON into a custom type. Signed-off-by: Max Jonas Werner --- cmd/flux/check_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/flux/check_test.go b/cmd/flux/check_test.go index 41b885ab..abfd8463 100644 --- a/cmd/flux/check_test.go +++ b/cmd/flux/check_test.go @@ -22,11 +22,9 @@ package main import ( "context" "encoding/json" - "strings" "testing" "github.com/fluxcd/flux2/internal/utils" - "k8s.io/apimachinery/pkg/version" ) func TestCheckPre(t *testing.T) { @@ -35,17 +33,17 @@ func TestCheckPre(t *testing.T) { t.Fatalf("Error running utils.ExecKubectlCommand: %v", err.Error()) } - var versions map[string]version.Info + var versions map[string]interface{} if err := json.Unmarshal([]byte(jsonOutput), &versions); err != nil { t.Fatalf("Error unmarshalling '%s': %v", jsonOutput, err.Error()) } - serverVersion := strings.TrimPrefix(versions["serverVersion"].GitVersion, "v") + serverGitVersion := versions["serverVersion"].(map[string]interface{})["gitVersion"].(string) cmd := cmdTestCase{ args: "check --pre", assert: assertGoldenTemplateFile("testdata/check/check_pre.golden", map[string]string{ - "serverVersion": serverVersion, + "serverVersion": serverGitVersion, }), } cmd.runTestCmd(t) From e35da1c8904e20955ddf811db225aae587e30dac Mon Sep 17 00:00:00 2001 From: Max Jonas Werner Date: Wed, 18 May 2022 17:08:50 +0200 Subject: [PATCH 3/3] trim prefix from server version It's not part of the `flux check` output. Signed-off-by: Max Jonas Werner --- cmd/flux/check_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/flux/check_test.go b/cmd/flux/check_test.go index abfd8463..50aac200 100644 --- a/cmd/flux/check_test.go +++ b/cmd/flux/check_test.go @@ -22,6 +22,7 @@ package main import ( "context" "encoding/json" + "strings" "testing" "github.com/fluxcd/flux2/internal/utils" @@ -38,7 +39,9 @@ func TestCheckPre(t *testing.T) { t.Fatalf("Error unmarshalling '%s': %v", jsonOutput, err.Error()) } - serverGitVersion := versions["serverVersion"].(map[string]interface{})["gitVersion"].(string) + serverGitVersion := strings.TrimPrefix( + versions["serverVersion"].(map[string]interface{})["gitVersion"].(string), + "v") cmd := cmdTestCase{ args: "check --pre",