mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 22:05:25 +00:00
Merge pull request #453 from nrb/fix-444
Make empty excludes string more accurate
This commit is contained in:
@@ -79,18 +79,18 @@ func (ie *IncludesExcludes) ShouldInclude(s string) bool {
|
||||
// IncludesString returns a string containing all of the includes, separated by commas, or * if the
|
||||
// list is empty.
|
||||
func (ie *IncludesExcludes) IncludesString() string {
|
||||
return asString(ie.GetIncludes())
|
||||
return asString(ie.GetIncludes(), "*")
|
||||
}
|
||||
|
||||
// ExcludesString returns a string containing all of the excludes, separated by commas, or * if the
|
||||
// ExcludesString returns a string containing all of the excludes, separated by commas, or <none> if the
|
||||
// list is empty.
|
||||
func (ie *IncludesExcludes) ExcludesString() string {
|
||||
return asString(ie.GetExcludes())
|
||||
return asString(ie.GetExcludes(), "<none>")
|
||||
}
|
||||
|
||||
func asString(in []string) string {
|
||||
func asString(in []string, empty string) string {
|
||||
if len(in) == 0 {
|
||||
return "*"
|
||||
return empty
|
||||
}
|
||||
return strings.Join(in, ", ")
|
||||
}
|
||||
|
||||
@@ -135,3 +135,36 @@ func TestValidateIncludesExcludes(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncludeExcludeString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
includes []string
|
||||
excludes []string
|
||||
expectedIncludes string
|
||||
expectedExcludes string
|
||||
}{
|
||||
{
|
||||
name: "unspecified includes/excludes should return '*'/'<none>'",
|
||||
includes: nil,
|
||||
excludes: nil,
|
||||
expectedIncludes: "*",
|
||||
expectedExcludes: "<none>",
|
||||
},
|
||||
{
|
||||
name: "specific resources should result in sorted joined string",
|
||||
includes: []string{"foo", "bar"},
|
||||
excludes: []string{"baz", "xyz"},
|
||||
expectedIncludes: "bar, foo",
|
||||
expectedExcludes: "baz, xyz",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ie := NewIncludesExcludes().Includes(test.includes...).Excludes(test.excludes...)
|
||||
assert.Equal(t, test.expectedIncludes, ie.IncludesString())
|
||||
assert.Equal(t, test.expectedExcludes, ie.ExcludesString())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user