Skip to content

Commit

Permalink
fix: fix args name in postrender/exec_test.go and error if order in p…
Browse files Browse the repository at this point in the history
…ostRendererArgsSlice

Signed-off-by: guofutan <guofutan@tencent.com>
  • Loading branch information
guofutan committed Jan 22, 2022
1 parent d12170b commit 04e79e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 7 additions & 2 deletions cmd/helm/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions pkg/postrender/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`

Expand Down Expand Up @@ -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) {
Expand All @@ -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()) {
Expand Down

0 comments on commit 04e79e9

Please sign in to comment.