From c5bdd1da15b8e7b67b0cf10f9a948b7ae677acf8 Mon Sep 17 00:00:00 2001 From: Sergej Jevsejev Date: Mon, 30 Oct 2017 22:30:44 +0100 Subject: [PATCH] Added a test for proper `%s` handling when display last applied configuration --- pkg/kubectl/cmd/apply_test.go | 31 +++++++++++++------ .../pkg/kubectl/cmd/apply/rc-args.yaml | 20 ++++++++++++ .../cmd/apply/rc-lastapplied-args.yaml | 23 ++++++++++++++ 3 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 test/fixtures/pkg/kubectl/cmd/apply/rc-args.yaml create mode 100644 test/fixtures/pkg/kubectl/cmd/apply/rc-lastapplied-args.yaml diff --git a/pkg/kubectl/cmd/apply_test.go b/pkg/kubectl/cmd/apply_test.go index fc98f462f9b..c5c347a34de 100644 --- a/pkg/kubectl/cmd/apply_test.go +++ b/pkg/kubectl/cmd/apply_test.go @@ -63,15 +63,17 @@ func validateApplyArgs(cmd *cobra.Command, args []string) error { } const ( - filenameRC = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc.yaml" - filenameRCNoAnnotation = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-no-annotation.yaml" - filenameRCLASTAPPLIED = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-lastapplied.yaml" - filenameSVC = "../../../test/fixtures/pkg/kubectl/cmd/apply/service.yaml" - filenameRCSVC = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-service.yaml" - filenameNoExistRC = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-noexist.yaml" - filenameRCPatchTest = "../../../test/fixtures/pkg/kubectl/cmd/apply/patch.json" - dirName = "../../../test/fixtures/pkg/kubectl/cmd/apply/testdir" - filenameRCJSON = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc.json" + filenameRC = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc.yaml" + filenameRCArgs = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-args.yaml" + filenameRCLastAppliedArgs = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-lastapplied-args.yaml" + filenameRCNoAnnotation = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-no-annotation.yaml" + filenameRCLASTAPPLIED = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-lastapplied.yaml" + filenameSVC = "../../../test/fixtures/pkg/kubectl/cmd/apply/service.yaml" + filenameRCSVC = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-service.yaml" + filenameNoExistRC = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-noexist.yaml" + filenameRCPatchTest = "../../../test/fixtures/pkg/kubectl/cmd/apply/patch.json" + dirName = "../../../test/fixtures/pkg/kubectl/cmd/apply/testdir" + filenameRCJSON = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc.json" filenameWidgetClientside = "../../../test/fixtures/pkg/kubectl/cmd/apply/widget-clientside.yaml" filenameWidgetServerside = "../../../test/fixtures/pkg/kubectl/cmd/apply/widget-serverside.yaml" @@ -229,6 +231,7 @@ func walkMapPath(t *testing.T, start map[string]interface{}, path []string) map[ func TestRunApplyViewLastApplied(t *testing.T) { _, rcBytesWithConfig := readReplicationController(t, filenameRCLASTAPPLIED) + _, rcBytesWithArgs := readReplicationController(t, filenameRCLastAppliedArgs) nameRC, rcBytes := readReplicationController(t, filenameRC) pathRC := "/namespaces/test/replicationcontrollers/" + nameRC @@ -247,6 +250,16 @@ func TestRunApplyViewLastApplied(t *testing.T) { args: []string{}, respBytes: rcBytesWithConfig, }, + { + name: "test with file include `%s` in arguments", + filePath: filenameRCArgs, + outputFormat: "", + expectedErr: "", + expectedOut: "args: -random_flag=%s@domain.com\n", + selector: "", + args: []string{}, + respBytes: rcBytesWithArgs, + }, { name: "view with file json format", filePath: filenameRC, diff --git a/test/fixtures/pkg/kubectl/cmd/apply/rc-args.yaml b/test/fixtures/pkg/kubectl/cmd/apply/rc-args.yaml new file mode 100644 index 00000000000..84688732835 --- /dev/null +++ b/test/fixtures/pkg/kubectl/cmd/apply/rc-args.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: test-rc + labels: + name: test-rc +spec: + replicas: 1 + template: + metadata: + labels: + name: test-rc + spec: + containers: + - name: test-rc + image: nginx + args: + - -random_flag=%s@domain.com + ports: + - containerPort: 80 diff --git a/test/fixtures/pkg/kubectl/cmd/apply/rc-lastapplied-args.yaml b/test/fixtures/pkg/kubectl/cmd/apply/rc-lastapplied-args.yaml new file mode 100644 index 00000000000..16e1d7ba899 --- /dev/null +++ b/test/fixtures/pkg/kubectl/cmd/apply/rc-lastapplied-args.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"args":"-random_flag=%s@domain.com"} + name: test-rc + labels: + name: test-rc +spec: + replicas: 1 + template: + metadata: + labels: + name: test-rc + spec: + containers: + - name: test-rc + image: nginx + args: + - -random_flag=%s@domain.com + ports: + - containerPort: 80