Skip to content

Commit

Permalink
set label filter to nil when it is empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
linglingye001 committed Sep 10, 2024
1 parent 31dff71 commit 09ae2e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions internal/loader/configuraiton_setting_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ func TestGetFilters(t *testing.T) {
two := "two"
three := "three"
labelString := "test"
emptyLabel := ""
testSpec := acpv1.AzureAppConfigurationProviderSpec{
Configuration: acpv1.AzureAppConfigurationKeyValueOptions{
Selectors: []acpv1.Selector{
Expand Down Expand Up @@ -1324,6 +1325,19 @@ func TestGetFilters(t *testing.T) {
assert.Equal(t, "test", *filters6[0].LabelFilter)
assert.Equal(t, "one", *filters6[1].KeyFilter)
assert.Nil(t, filters6[1].LabelFilter)

testSpec7 := acpv1.AzureAppConfigurationProviderSpec{
Configuration: acpv1.AzureAppConfigurationKeyValueOptions{
Selectors: []acpv1.Selector{
{KeyFilter: &one, LabelFilter: &emptyLabel},
},
},
}

filters7 := GetKeyValueFilters(testSpec7)
assert.Len(t, filters7, 1)
assert.Equal(t, "one", *filters7[0].KeyFilter)
assert.Nil(t, filters7[0].LabelFilter)
}

func TestCompare(t *testing.T) {
Expand Down
10 changes: 9 additions & 1 deletion internal/loader/configuration_setting_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,15 @@ func deduplicateFilters(filters []acpv1.Selector) []acpv1.Selector {
}
}
if !findDuplicate {
result = append(result, filters[i])
labelFilter := filters[i].LabelFilter
// need to check if labelFilter is empty, if so, set it to nil
if labelFilter != nil && len(*labelFilter) == 0 {
labelFilter = nil
}
result = append(result, acpv1.Selector{
KeyFilter: filters[i].KeyFilter,
LabelFilter: labelFilter,
})
}
}
reverse(result)
Expand Down

0 comments on commit 09ae2e0

Please sign in to comment.