Make backupType case insensitive in the CLI. (#10189)
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
e2e-test-kind.yaml / extract (push) Failing after 8s
Run the E2E test on kind / get-go-version (push) Failing after 9s
Run the E2E test on kind / build (push) Skipped
Run the E2E test on kind / run-e2e-test (push) Skipped
push.yml / extract (push) Failing after 6s
Main CI / get-go-version (push) Failing after 7s
Main CI / Build (push) Skipped

Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
This commit is contained in:
Xun Jiang/Bruce Jiang
2026-08-10 16:29:13 -04:00
committed by GitHub
parent 9a549f781f
commit 40de7f9f97
2 changed files with 18 additions and 8 deletions
+8 -2
View File
@@ -242,11 +242,17 @@ func (o *CreateOptions) validateFromScheduleFlag(c *cobra.Command) error {
return nil
}
// validateBackupType check the backupType value and return the valid value.
func (o *CreateOptions) validateBackupType() error {
backupType := strings.TrimSpace(o.BackupType)
// Allow full, and incremental from the CLI, and ignore case of the input string's case.
backupType := strings.ToLower(strings.TrimSpace(o.BackupType))
switch backupType {
case "", "Incremental", "Full":
case "":
case "incremental":
o.BackupType = string(velerov1api.BackupTypeIncremental)
case "full":
o.BackupType = string(velerov1api.BackupTypeFull)
default:
return fmt.Errorf("invalid backup type %s - valid values are 'Incremental', and 'Full'", backupType)
}
+10 -6
View File
@@ -129,30 +129,34 @@ func TestCreateOptions_ValidateBackupType(t *testing.T) {
o.BackupType = ""
err := o.validateBackupType()
require.NoError(t, err)
require.Empty(t, o.BackupType)
o.BackupType = "Incremental"
err = o.validateBackupType()
require.NoError(t, err)
require.EqualValues(t, velerov1api.BackupTypeIncremental, o.BackupType)
o.BackupType = "Full"
err = o.validateBackupType()
require.NoError(t, err)
require.EqualValues(t, velerov1api.BackupTypeFull, o.BackupType)
o.BackupType = " Incremental "
err = o.validateBackupType()
require.NoError(t, err)
require.EqualValues(t, velerov1api.BackupTypeIncremental, o.BackupType)
o.BackupType = "iNcReMeNtAl"
err = o.validateBackupType()
require.NoError(t, err)
require.EqualValues(t, velerov1api.BackupTypeIncremental, o.BackupType)
})
t.Run("invalid backup type", func(t *testing.T) {
o := NewCreateOptions()
o.BackupType = "incremental"
err := o.validateBackupType()
require.Error(t, err)
require.Equal(t, "invalid backup type incremental - valid values are 'Incremental', and 'Full'", err.Error())
o.BackupType = "invalid"
err = o.validateBackupType()
err := o.validateBackupType()
require.Error(t, err)
require.Equal(t, "invalid backup type invalid - valid values are 'Incremental', and 'Full'", err.Error())
})