Skip to content

Commit a778f80

Browse files
authored
Merge pull request #1681 from saschagrunert/slices
Use `slices.Compact` instead of own logic
2 parents 98761db + 48e7ac9 commit a778f80

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

pkg/validate/image.go

Lines changed: 4 additions & 18 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,8 @@ 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)
171+
slices.Sort(ids)
172+
ids = slices.Compact(ids)
172173
Expect(ids).To(HaveLen(1), "Only 1 image id should be returned")
173174

174175
defer removeImageList(c, testDifferentTagSameImageList)
@@ -216,8 +217,7 @@ func testPullPublicImage(c internalapi.ImageManagerService, imageName string, po
216217
}
217218

218219
// pullImageList pulls the images listed in the imageList.
219-
func pullImageList(c internalapi.ImageManagerService, imageList []string, podConfig *runtimeapi.PodSandboxConfig) []string {
220-
ids := []string{}
220+
func pullImageList(c internalapi.ImageManagerService, imageList []string, podConfig *runtimeapi.PodSandboxConfig) (ids []string) {
221221
for _, imageName := range imageList {
222222
ids = append(ids, framework.PullPublicImage(c, imageName, podConfig))
223223
}
@@ -243,17 +243,3 @@ func removeImage(c internalapi.ImageManagerService, imageName string) {
243243
framework.ExpectNoError(err, "failed to remove image: %v", err)
244244
}
245245
}
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)