Merge pull request #453 from nrb/fix-444

Make empty excludes string more accurate
This commit is contained in:
Andy Goldstein
2018-04-24 14:53:33 -04:00
committed by GitHub
2 changed files with 38 additions and 5 deletions

View File

@@ -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, ", ")
}

View File

@@ -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())
})
}
}