BACKPORT-CONFLICT

This commit is contained in:
Xun Jiang/Bruce Jiang
2026-08-11 19:50:25 +00:00
committed by github-actions[bot]
parent 0fb6a37bbf
commit 884732b253
2 changed files with 64 additions and 0 deletions
+21
View File
@@ -231,6 +231,27 @@ func (o *CreateOptions) validateFromScheduleFlag(c *cobra.Command) error {
return nil
}
<<<<<<< HEAD
=======
// validateBackupType check the backupType value and return the valid value.
func (o *CreateOptions) validateBackupType() error {
// 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 "":
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)
}
return nil
}
>>>>>>> 40de7f9f9 (Make backupType case insensitive in the CLI. (#10189))
func (o *CreateOptions) Complete(args []string, f client.Factory) error {
// If an explicit name is specified, use that name
if len(args) > 0 {
+43
View File
@@ -122,6 +122,49 @@ func TestCreateOptions_ValidateFromScheduleFlag(t *testing.T) {
})
}
<<<<<<< HEAD
=======
func TestCreateOptions_ValidateBackupType(t *testing.T) {
t.Run("valid backup types", func(t *testing.T) {
o := NewCreateOptions()
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 = "invalid"
err := o.validateBackupType()
require.Error(t, err)
require.Equal(t, "invalid backup type invalid - valid values are 'Incremental', and 'Full'", err.Error())
})
}
>>>>>>> 40de7f9f9 (Make backupType case insensitive in the CLI. (#10189))
func TestCreateOptions_BuildBackupFromSchedule(t *testing.T) {
o := NewCreateOptions()
o.FromSchedule = "test"