From b5095c04a40f96ecdb628579e58a9e3e1535ff39 Mon Sep 17 00:00:00 2001 From: yxxhero Date: Sat, 23 Dec 2023 07:20:04 +0800 Subject: [PATCH] fix tests Signed-off-by: yxxhero --- cmd/apply.go | 2 +- pkg/state/helmx.go | 9 +++++++++ pkg/state/helmx_test.go | 16 ++++++---------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd/apply.go b/cmd/apply.go index 91ec96a0..6ee8ac3e 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -70,7 +70,7 @@ func NewApplyCmd(globalCfg *config.GlobalImpl) *cobra.Command { f.StringArrayVar(&applyOptions.PostRendererArgs, "post-renderer-args", nil, `pass --post-renderer-args to "helm template" or "helm upgrade --install"`) f.StringVar(&applyOptions.Cascade, "cascade", "", "pass cascade to helm exec, default: background") f.StringArrayVar(&applyOptions.SuppressOutputLineRegex, "suppress-output-line-regex", nil, "a list of regex patterns to suppress output lines from the diff output") - f.StringVar(&applyOptions.DryRyn, "dry-run", "", "pass dry-run to helm exec") + f.StringVar(&applyOptions.DryRun, "dry-run", "", "pass dry-run to helm exec") return cmd } diff --git a/pkg/state/helmx.go b/pkg/state/helmx.go index 2ac9e26a..fc128339 100644 --- a/pkg/state/helmx.go +++ b/pkg/state/helmx.go @@ -89,6 +89,11 @@ func (st *HelmState) appendWaitForJobsFlags(flags []string, release *ReleaseSpec return flags } +// appendWaitFlags appends the appropriate wait flags to the given flags slice based on the provided release and sync options. +// If release.Wait is true, "--wait" flag is added. +// If ops.Wait is true, "--wait" flag is added. +// If release.Wait is nil and st.HelmDefaults.Wait is true, "--wait" flag is added. +// Returns the updated flags slice. func (st *HelmState) appendWaitFlags(flags []string, release *ReleaseSpec, ops *SyncOpts) []string { switch { case release.Wait != nil && *release.Wait: @@ -100,6 +105,10 @@ func (st *HelmState) appendWaitFlags(flags []string, release *ReleaseSpec, ops * } return flags } + +// appendDryRunFlags appends the necessary flags for a dry run to the given flags slice. +// If the opt parameter is not nil and opt.DryRun is not empty, the "--dry-run" flag and the value of opt.DryRun are appended to the flags slice. +// The updated flags slice is returned. func (st *HelmState) appendDryRunFlags(flags []string, opt *SyncOpts) []string { if opt != nil && opt.DryRun != "" { flags = append(flags, "--dry-run", opt.DryRun) diff --git a/pkg/state/helmx_test.go b/pkg/state/helmx_test.go index d3c8d8e2..0a94c106 100644 --- a/pkg/state/helmx_test.go +++ b/pkg/state/helmx_test.go @@ -279,9 +279,7 @@ func TestAppendShowOnlyFlags(t *testing.T) { func TestAppendDryRunFlags(t *testing.T) { type args struct { - flags []string - dry-run string - helm helmexec.Interface + dryRun string expected []string } tests := []struct { @@ -291,18 +289,14 @@ func TestAppendDryRunFlags(t *testing.T) { { name: "do dry-run on client", args: args{ - flags: []string{}, - dry-run: "client", - helm: testutil.NewVersionHelmExec("3.12.1"), + dryRun: "client", expected: []string{"--dry-run", "client"}, }, }, { name: "do dry-run on server", args: args{ - flags: []string{}, - dry-run: "server", - helm: testutil.NewVersionHelmExec("3.12.1"), + dryRun: "server", expected: []string{"--dry-run", "server"}, }, }, @@ -310,7 +304,9 @@ func TestAppendDryRunFlags(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { st := &HelmState{} - got := st.appendDryRunFlags(tt.args.flags, tt.args.helm, tt.args.release, tt.args.dry-run) + got := st.appendDryRunFlags([]string{}, &SyncOpts{ + DryRun: tt.args.dryRun, + }) require.Equalf(t, tt.args.expected, got, "appendDryRunFlags() = %v, want %v", got, tt.args.expected) }) }