fix tests

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2024-06-02 15:03:54 +08:00
parent 4b3ad24bc7
commit b5095c04a4
3 changed files with 16 additions and 11 deletions
+9
View File
@@ -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)
+6 -10
View File
@@ -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)
})
}