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 <mail@makk.es>
pull/2748/head
Max Jonas Werner 3 years ago
parent e1def4f8ac
commit 9af6175302
No known key found for this signature in database
GPG Key ID: EB525E0F02B52140

@ -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)

Loading…
Cancel
Save