fix(#510): fix golangci-lint run error,add the unit test, add the compatibility when there is blank in the args values.
Signed-off-by: guofutan <guofutan@tencent.com> Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
7be64f29cf
commit
4cc07daced
|
|
@ -133,18 +133,22 @@ func New(helmBinary string, enableLiveOutput bool, logger *zap.SugaredLogger, ku
|
|||
|
||||
func (helm *execer) SetExtraArgs(args ...string) {
|
||||
var extraArgs []string
|
||||
|
||||
// reset the postRenderers and filter the post-renderer args from args and put into helm.postRenderers
|
||||
helm.postRenderers = nil
|
||||
for _, arg := range args {
|
||||
if strings.HasPrefix(arg, "--post-renderer=") || strings.HasPrefix(arg, "--post-renderer-args=") {
|
||||
helm.postRenderers = append(helm.postRenderers, arg)
|
||||
continue
|
||||
var renderArgs []string
|
||||
// reset the postRenderers and filter --post-renderer=xx or --post-renderer xxx from args and put into helm.postRenderers
|
||||
for i := 0; i < len(args); i++ {
|
||||
if strings.HasPrefix(args[i], "--post-renderer=") || strings.HasPrefix(args[i], "--post-renderer-args=") {
|
||||
renderArgs = append(renderArgs, args[i])
|
||||
} else if (args[i] == "--post-renderer" || args[i] == "--post-renderer-args") && i < len(args)-1 {
|
||||
renderArgs = append(renderArgs, args[i])
|
||||
renderArgs = append(renderArgs, args[i+1])
|
||||
i++
|
||||
} else {
|
||||
extraArgs = append(extraArgs, args[i])
|
||||
}
|
||||
extraArgs = append(extraArgs, arg)
|
||||
}
|
||||
|
||||
helm.extra = extraArgs
|
||||
helm.postRenderers = renderArgs
|
||||
}
|
||||
|
||||
func (helm *execer) SetHelmBinary(bin string) {
|
||||
|
|
@ -263,7 +267,7 @@ func (helm *execer) SyncRelease(context HelmContext, name, chart string, flags .
|
|||
} else {
|
||||
env["HELM_TILLER_HISTORY_MAX"] = strconv.Itoa(context.HistoryMax)
|
||||
}
|
||||
|
||||
|
||||
if helm.IsHelm3() {
|
||||
flags = append(flags, helm.postRenderers...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,29 @@ func Test_SetExtraArgs(t *testing.T) {
|
|||
if !reflect.DeepEqual(helm.extra, []string{"alpha", "beta"}) {
|
||||
t.Error("helmexec.SetExtraArgs() - two extra arguments missing (overwriting the previous value)")
|
||||
}
|
||||
|
||||
helm.SetExtraArgs("--post-renderer=aaa")
|
||||
fmt.Println(helm.postRenderers)
|
||||
if !reflect.DeepEqual(helm.postRenderers, []string{"--post-renderer=aaa"}) {
|
||||
t.Error("helmexec.SetExtraArgs() - post-renderer assign arguments missing ")
|
||||
}
|
||||
|
||||
helm.SetExtraArgs("--post-renderer", "aaa")
|
||||
fmt.Println(helm.postRenderers)
|
||||
if !reflect.DeepEqual(helm.postRenderers, []string{"--post-renderer", "aaa"}) {
|
||||
t.Error("helmexec.SetExtraArgs() - post-renderer blank arguments missing ")
|
||||
}
|
||||
|
||||
helm.SetExtraArgs("--post-renderer-args=bbb")
|
||||
fmt.Println(helm.postRenderers)
|
||||
if !reflect.DeepEqual(helm.postRenderers, []string{"--post-renderer-args=bbb"}) {
|
||||
t.Error("helmexec.SetExtraArgs() - post-renderer-args assign arguments missing")
|
||||
}
|
||||
|
||||
helm.SetExtraArgs("--post-renderer", "aaa", "--post-renderer-args=bbb")
|
||||
if !reflect.DeepEqual(helm.postRenderers, []string{"--post-renderer", "aaa", "--post-renderer-args=bbb"}) {
|
||||
t.Error("helmexec.SetExtraArgs() - post-renderer arguments not be set correct")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_SetHelmBinary(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue