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:
parent
9b4a8982b9
commit
88c55c2b9d
1 changed files with 22 additions and 0 deletions
|
@ -73,9 +73,31 @@ func LoadTest(fs billy.Filesystem, path string) TestCase {
|
||||||
Err: err,
|
Err: err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cleanTest(&test)
|
||||||
return TestCase{
|
return TestCase{
|
||||||
Path: path,
|
Path: path,
|
||||||
Fs: fs,
|
Fs: fs,
|
||||||
Test: &test,
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue