Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ func GetIgnoredResourcesList() (List, error) {
return nil, errors.New("'resources-to-ignore' only accepts 'configMaps' or 'secrets', not both")
}

return ignoredResourcesList, nil
normalizedList := make(List, len(ignoredResourcesList))
for i, v := range ignoredResourcesList {
normalizedList[i] = strings.ToLower(v)
}

return normalizedList, nil
}

func GetIgnoredWorkloadTypesList() (List, error) {
Expand Down
75 changes: 75 additions & 0 deletions internal/pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,81 @@ func TestGetIgnoredWorkloadTypesList(t *testing.T) {
}
}

func TestGetIgnoredResourcesList(t *testing.T) {
originalResources := options.ResourcesToIgnore
defer func() {
options.ResourcesToIgnore = originalResources
}()

tests := []struct {
name string
resources []string
expectError bool
expected []string
}{
{
name: "configMaps normalized to lowercase",
resources: []string{"configMaps"},
expectError: false,
expected: []string{"configmaps"},
},
{
name: "secrets stays lowercase",
resources: []string{"secrets"},
expectError: false,
expected: []string{"secrets"},
},
{
name: "Empty list",
resources: []string{},
expectError: false,
expected: []string{},
},
{
name: "Invalid resource",
resources: []string{"invalid"},
expectError: true,
expected: nil,
},
{
name: "Both resources - error",
resources: []string{"configMaps", "secrets"},
expectError: true,
expected: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
options.ResourcesToIgnore = tt.resources

result, err := GetIgnoredResourcesList()

if tt.expectError && err == nil {
t.Errorf("Expected error but got none")
}

if !tt.expectError && err != nil {
t.Errorf("Expected no error but got: %v", err)
}

if !tt.expectError {
if len(result) != len(tt.expected) {
t.Errorf("Expected %v, got %v", tt.expected, result)
return
}

for i, expected := range tt.expected {
if i >= len(result) || result[i] != expected {
t.Errorf("Expected %v, got %v", tt.expected, result)
break
}
}
}
})
}
}

func TestListContains(t *testing.T) {
tests := []struct {
name string
Expand Down