mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
fix: fix args name in postrender/exec_test.go and error if order in postRendererArgsSlice
Signed-off-by: guofutan <guofutan@tencent.com>
This commit is contained in:
parent
d12170b3f2
commit
04e79e936d
2 changed files with 12 additions and 7 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue