mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-20 23:14:17 +00:00
Merge branch 'main' into fix/backup-name-validation
This commit is contained in:
@@ -416,8 +416,19 @@ func ParseOrderedResources(orderMapStr string) (map[string]string, error) {
|
||||
return nil, fmt.Errorf("invalid OrderedResources '%s'", entry)
|
||||
}
|
||||
kind := strings.TrimSpace(kv[0])
|
||||
order := strings.TrimSpace(kv[1])
|
||||
orderedResources[kind] = order
|
||||
orderParts := strings.Split(kv[1], ",")
|
||||
cleaned := make([]string, 0, len(orderParts))
|
||||
for _, part := range orderParts {
|
||||
name := strings.TrimSpace(part)
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
cleaned = append(cleaned, name)
|
||||
}
|
||||
if kind == "" || len(cleaned) == 0 {
|
||||
return nil, fmt.Errorf("invalid OrderedResources '%s'", entry)
|
||||
}
|
||||
orderedResources[kind] = strings.Join(cleaned, ",")
|
||||
}
|
||||
return orderedResources, nil
|
||||
}
|
||||
|
||||
@@ -234,6 +234,14 @@ func TestCreateOptions_OrderedResources(t *testing.T) {
|
||||
"persistentvolumes": "pv1,pv2",
|
||||
}
|
||||
assert.Equal(t, expectedMixedResources, orderedResources)
|
||||
|
||||
// Spaces after commas in the resource list must be trimmed.
|
||||
orderedResources, err = ParseOrderedResources("pods=ns1/p1, ns1/p2 ; persistentvolumeclaims= ns2/pvc1, ns2/pvc2")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, map[string]string{
|
||||
"pods": "ns1/p1,ns1/p2",
|
||||
"persistentvolumeclaims": "ns2/pvc1,ns2/pvc2",
|
||||
}, orderedResources)
|
||||
}
|
||||
|
||||
func TestCreateCommand(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user