Skip to content

Commit

Permalink
Make empty excludes string more accurate
Browse files Browse the repository at this point in the history
Signed-off-by: Nolan Brubaker <[email protected]>
  • Loading branch information
Nolan Brubaker committed Apr 24, 2018
1 parent dc8c66b commit 20bc588
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/util/collections/includes_excludes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ", ")
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/util/collections/includes_excludes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}
}

0 comments on commit 20bc588

Please sign in to comment.