mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-13 03:24:39 +00:00
move backup name validation to Args to run before cluster contact, and validate regardless of --from-schedule
Signed-off-by: samay43 <samayrbhat43@gmail.com>
This commit is contained in:
@@ -46,7 +46,17 @@ func NewCreateCommand(f client.Factory, use string) *cobra.Command {
|
||||
c := &cobra.Command{
|
||||
Use: use + " NAME",
|
||||
Short: "Create a backup",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Args: func(c *cobra.Command, args []string) error {
|
||||
if err := cobra.MaximumNArgs(1)(c, args); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args) == 1 {
|
||||
if errs := validation.IsDNS1123Subdomain(args[0]); len(errs) > 0 {
|
||||
return fmt.Errorf("invalid backup name %q: %s", args[0], strings.Join(errs, "; "))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
cmd.CheckError(o.Complete(args, f))
|
||||
cmd.CheckError(o.Validate(c, args, f))
|
||||
|
||||
@@ -233,7 +233,7 @@ func TestCreateOptions_OrderedResources(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateCommand(t *testing.T) {
|
||||
name := "nameToBeCreated"
|
||||
name := "name-to-be-created"
|
||||
args := []string{name}
|
||||
|
||||
t.Run("create a backup create command with full options except fromSchedule and wait, then run by create option", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user