From ec46b37855319eab682d8501218acb9972aaa73f Mon Sep 17 00:00:00 2001 From: Benjamin Thuillier Date: Wed, 5 Jun 2024 16:36:31 +0200 Subject: [PATCH] fix issue on apiVersion where apiVersion is put at the end --- printutils/printYaml.go | 2 +- printutils/printYaml_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/printutils/printYaml.go b/printutils/printYaml.go index 37ad2d5..79784a9 100644 --- a/printutils/printYaml.go +++ b/printutils/printYaml.go @@ -35,7 +35,7 @@ func printResource(w io.Writer, data interface{}) error { if !ok { fmt.Fprint(w, string(yamlBytes)) } else { - wantedKeys := []string{"version", "kind", "metadata", "spec"} + wantedKeys := []string{"apiVersion", "kind", "metadata", "spec"} for _, wantedKey := range wantedKeys { printKeyYaml(w, wantedKey, asMap[wantedKey]) } diff --git a/printutils/printYaml_test.go b/printutils/printYaml_test.go index 5418425..ac077bb 100644 --- a/printutils/printYaml_test.go +++ b/printutils/printYaml_test.go @@ -8,7 +8,7 @@ import ( ) func TestPrintResourceLikeYamlOnSingleResource(t *testing.T) { - resourceFromBe := `{"spec": "someSpec", "version": "v4", "kind": "Gelato", "metadata": "arancia"}` + resourceFromBe := `{"spec": "someSpec", "apiVersion": "v4", "kind": "Gelato", "metadata": "arancia"}` var data interface{} err := json.Unmarshal([]byte(resourceFromBe), &data) if err != nil { @@ -17,7 +17,7 @@ func TestPrintResourceLikeYamlOnSingleResource(t *testing.T) { var output bytes.Buffer PrintResourceLikeYamlFile(&output, data) expected := strings.TrimSpace(` -version: v4 +apiVersion: v4 kind: Gelato metadata: arancia spec: someSpec`) @@ -52,7 +52,7 @@ cat`) } func TestPrintResourceLikeYamlOnMultileResources(t *testing.T) { - resourceFromBe := `{"spec": "someSpec", "version": "v4", "newKind": "Gelato", "metadata": "arancia"}` + resourceFromBe := `{"spec": "someSpec", "apiVersion": "v4", "newKind": "Gelato", "metadata": "arancia"}` var data interface{} err := json.Unmarshal([]byte(resourceFromBe), &data) if err != nil { @@ -61,7 +61,7 @@ func TestPrintResourceLikeYamlOnMultileResources(t *testing.T) { var output bytes.Buffer PrintResourceLikeYamlFile(&output, data) expected := strings.TrimSpace(` -version: v4 +apiVersion: v4 metadata: arancia spec: someSpec newKind: Gelato