From 04e79e936d59d953339cc5b283327bb4b6a64f2d Mon Sep 17 00:00:00 2001 From: guofutan Date: Sat, 22 Jan 2022 11:45:15 +0800 Subject: [PATCH] fix: fix args name in postrender/exec_test.go and error if order in postRendererArgsSlice Signed-off-by: guofutan --- cmd/helm/flags.go | 9 +++++++-- pkg/postrender/exec_test.go | 10 +++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/helm/flags.go b/cmd/helm/flags.go index f370125d3..a432535ed 100644 --- a/cmd/helm/flags.go +++ b/cmd/helm/flags.go @@ -117,7 +117,7 @@ func (o *outputValue) Set(s string) error { func bindPostRenderFlag(cmd *cobra.Command, varRef *postrender.PostRenderer) { p := &postRendererOptions{varRef, "", []string{}} cmd.Flags().Var(&postRendererString{p}, postRenderFlag, "the path to an executable to be used for post rendering. If it exists in $PATH, the binary will be used, otherwise it will try to look for the executable at the given path") - cmd.Flags().Var(&postRendererArgsSlice{p}, postRenderArgsFlag, "the args to an executable to be used for post rendering. (can specify multiple)") + cmd.Flags().Var(&postRendererArgsSlice{p}, postRenderArgsFlag, "an argument to the post-renderer (can specify multiple)") } type postRendererOptions struct { @@ -164,10 +164,15 @@ func (p *postRendererArgsSlice) Type() string { } func (p *postRendererArgsSlice) Set(val string) error { - if val == "" || p.options.binaryPath == "" { + if val == "" { return nil } + p.options.args = append(p.options.args, val) + + if p.options.binaryPath == "" { + return nil + } // overwrite if already create PostRenderer by `post-renderer` flags pr, err := postrender.NewExec(p.options.binaryPath, p.options.args...) if err != nil { diff --git a/pkg/postrender/exec_test.go b/pkg/postrender/exec_test.go index 416845ffa..9788ed56e 100644 --- a/pkg/postrender/exec_test.go +++ b/pkg/postrender/exec_test.go @@ -34,7 +34,7 @@ const testingScript = `#!/bin/sh if [ $# -eq 0 ]; then sed s/FOOTEST/BARTEST/g <&0 else -sed s/FOOTEST/BARTEST$#/g <&0 +sed s/FOOTEST/"$*"/g <&0 fi ` @@ -137,12 +137,12 @@ func TestNewExecWithOneArgsRun(t *testing.T) { testpath, cleanup := setupTestingScript(t) defer cleanup() - renderer, err := NewExec(testpath, "FOOTEST") + renderer, err := NewExec(testpath, "ARG1") require.NoError(t, err) output, err := renderer.Run(bytes.NewBufferString("FOOTEST")) is.NoError(err) - is.Contains(output.String(), "BARTEST1") + is.Contains(output.String(), "ARG1") } func TestNewExecWithTwoArgsRun(t *testing.T) { @@ -154,12 +154,12 @@ func TestNewExecWithTwoArgsRun(t *testing.T) { testpath, cleanup := setupTestingScript(t) defer cleanup() - renderer, err := NewExec(testpath, "FOOTEST", "FOOTEST") + renderer, err := NewExec(testpath, "ARG1", "ARG2") require.NoError(t, err) output, err := renderer.Run(bytes.NewBufferString("FOOTEST")) is.NoError(err) - is.Contains(output.String(), "BARTEST2") + is.Contains(output.String(), "ARG1 ARG2") } func setupTestingScript(t *testing.T) (filepath string, cleanup func()) {