1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

fix/duplicate-test-entries-deduplication (#11709)

Signed-off-by: Darshan808 <pranishpoudel10@gmail.com>
Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
Darshan Poudel 2024-12-12 14:39:24 +05:45 committed by GitHub
parent 9b4a8982b9
commit 88c55c2b9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -73,9 +73,31 @@ func LoadTest(fs billy.Filesystem, path string) TestCase {
Err: err,
}
}
cleanTest(&test)
return TestCase{
Path: path,
Fs: fs,
Test: &test,
}
}
func cleanTest(test *v1alpha1.Test) {
test.Policies = removeDuplicateStrings(test.Policies)
test.Resources = removeDuplicateStrings(test.Resources)
for index, result := range test.Results {
test.Results[index].Resources = removeDuplicateStrings(result.Resources)
}
}
func removeDuplicateStrings(strings []string) []string {
seen := make(map[string]struct{})
var result []string
for _, str := range strings {
if _, exists := seen[str]; !exists {
seen[str] = struct{}{}
result = append(result, str)
}
}
return result
}