Skip to content

Commit 797a721

Browse files
committed
fix: Normalize resources-to-ignore values to match ResourceMap keys
1 parent 3dd2741 commit 797a721

2 files changed

Lines changed: 83 additions & 1 deletion

File tree

internal/pkg/util/util.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ func GetIgnoredResourcesList() (List, error) {
123123
return nil, errors.New("'resources-to-ignore' only accepts 'configMaps' or 'secrets', not both")
124124
}
125125

126-
return ignoredResourcesList, nil
126+
// Normalize to lowercase to match ResourceMap keys in pkg/kube/resourcemapper.go
127+
normalizedList := make(List, len(ignoredResourcesList))
128+
for i, v := range ignoredResourcesList {
129+
normalizedList[i] = strings.ToLower(v)
130+
}
131+
132+
return normalizedList, nil
127133
}
128134

129135
func GetIgnoredWorkloadTypesList() (List, error) {

internal/pkg/util/util_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,82 @@ func TestGetIgnoredWorkloadTypesList(t *testing.T) {
136136
}
137137
}
138138

139+
func TestGetIgnoredResourcesList(t *testing.T) {
140+
// Save original state
141+
originalResources := options.ResourcesToIgnore
142+
defer func() {
143+
options.ResourcesToIgnore = originalResources
144+
}()
145+
146+
tests := []struct {
147+
name string
148+
resources []string
149+
expectError bool
150+
expected []string
151+
}{
152+
{
153+
name: "configMaps normalized to lowercase",
154+
resources: []string{"configMaps"},
155+
expectError: false,
156+
expected: []string{"configmaps"},
157+
},
158+
{
159+
name: "secrets stays lowercase",
160+
resources: []string{"secrets"},
161+
expectError: false,
162+
expected: []string{"secrets"},
163+
},
164+
{
165+
name: "Empty list",
166+
resources: []string{},
167+
expectError: false,
168+
expected: []string{},
169+
},
170+
{
171+
name: "Invalid resource",
172+
resources: []string{"invalid"},
173+
expectError: true,
174+
expected: nil,
175+
},
176+
{
177+
name: "Both resources - error",
178+
resources: []string{"configMaps", "secrets"},
179+
expectError: true,
180+
expected: nil,
181+
},
182+
}
183+
184+
for _, tt := range tests {
185+
t.Run(tt.name, func(t *testing.T) {
186+
options.ResourcesToIgnore = tt.resources
187+
188+
result, err := GetIgnoredResourcesList()
189+
190+
if tt.expectError && err == nil {
191+
t.Errorf("Expected error but got none")
192+
}
193+
194+
if !tt.expectError && err != nil {
195+
t.Errorf("Expected no error but got: %v", err)
196+
}
197+
198+
if !tt.expectError {
199+
if len(result) != len(tt.expected) {
200+
t.Errorf("Expected %v, got %v", tt.expected, result)
201+
return
202+
}
203+
204+
for i, expected := range tt.expected {
205+
if i >= len(result) || result[i] != expected {
206+
t.Errorf("Expected %v, got %v", tt.expected, result)
207+
break
208+
}
209+
}
210+
}
211+
})
212+
}
213+
}
214+
139215
func TestListContains(t *testing.T) {
140216
tests := []struct {
141217
name string

0 commit comments

Comments
 (0)