Skip to content

Commit 21a2602

Browse files
committed
Use slices.Compact instead of own logic
The `slices` package can be used to remove duplicates. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
1 parent 98761db commit 21a2602

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

pkg/validate/image.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"runtime"
23+
"slices"
2324
"sort"
2425
"time"
2526

@@ -146,7 +147,6 @@ var _ = framework.KubeDescribe("Image Manager", func() {
146147
// Make sure test image does not exist.
147148
removeImageList(c, testDifferentTagDifferentImageList)
148149
ids := pullImageList(c, testDifferentTagDifferentImageList, testImagePodSandbox)
149-
ids = removeDuplicates(ids)
150150
Expect(ids).To(HaveLen(3), "3 image ids should be returned")
151151

152152
defer removeImageList(c, testDifferentTagDifferentImageList)
@@ -168,7 +168,6 @@ var _ = framework.KubeDescribe("Image Manager", func() {
168168
// Make sure test image does not exist.
169169
removeImageList(c, testDifferentTagSameImageList)
170170
ids := pullImageList(c, testDifferentTagSameImageList, testImagePodSandbox)
171-
ids = removeDuplicates(ids)
172171
Expect(ids).To(HaveLen(1), "Only 1 image id should be returned")
173172

174173
defer removeImageList(c, testDifferentTagSameImageList)
@@ -216,12 +215,12 @@ func testPullPublicImage(c internalapi.ImageManagerService, imageName string, po
216215
}
217216

218217
// pullImageList pulls the images listed in the imageList.
219-
func pullImageList(c internalapi.ImageManagerService, imageList []string, podConfig *runtimeapi.PodSandboxConfig) []string {
220-
ids := []string{}
218+
func pullImageList(c internalapi.ImageManagerService, imageList []string, podConfig *runtimeapi.PodSandboxConfig) (ids []string) {
221219
for _, imageName := range imageList {
222220
ids = append(ids, framework.PullPublicImage(c, imageName, podConfig))
223221
}
224-
return ids
222+
slices.Sort(ids)
223+
return slices.Compact(ids)
225224
}
226225

227226
// removeImageList removes the images listed in the imageList.
@@ -243,17 +242,3 @@ func removeImage(c internalapi.ImageManagerService, imageName string) {
243242
framework.ExpectNoError(err, "failed to remove image: %v", err)
244243
}
245244
}
246-
247-
// removeDuplicates remove duplicates strings from a list.
248-
func removeDuplicates(ss []string) []string {
249-
encountered := map[string]bool{}
250-
result := []string{}
251-
for _, s := range ss {
252-
if encountered[s] {
253-
continue
254-
}
255-
encountered[s] = true
256-
result = append(result, s)
257-
}
258-
return result
259-
}

0 commit comments

Comments
 (0)