From 9af61753020bc8a55531a451365f1474b0bc213d Mon Sep 17 00:00:00 2001 From: Max Jonas Werner Date: Wed, 18 May 2022 16:51:18 +0200 Subject: [PATCH] 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)