@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"fmt"
22
22
"runtime"
23
+ "slices"
23
24
"sort"
24
25
"time"
25
26
@@ -146,7 +147,6 @@ var _ = framework.KubeDescribe("Image Manager", func() {
146
147
// Make sure test image does not exist.
147
148
removeImageList (c , testDifferentTagDifferentImageList )
148
149
ids := pullImageList (c , testDifferentTagDifferentImageList , testImagePodSandbox )
149
- ids = removeDuplicates (ids )
150
150
Expect (ids ).To (HaveLen (3 ), "3 image ids should be returned" )
151
151
152
152
defer removeImageList (c , testDifferentTagDifferentImageList )
@@ -168,7 +168,8 @@ var _ = framework.KubeDescribe("Image Manager", func() {
168
168
// Make sure test image does not exist.
169
169
removeImageList (c , testDifferentTagSameImageList )
170
170
ids := pullImageList (c , testDifferentTagSameImageList , testImagePodSandbox )
171
- ids = removeDuplicates (ids )
171
+ slices .Sort (ids )
172
+ ids = slices .Compact (ids )
172
173
Expect (ids ).To (HaveLen (1 ), "Only 1 image id should be returned" )
173
174
174
175
defer removeImageList (c , testDifferentTagSameImageList )
@@ -216,8 +217,7 @@ func testPullPublicImage(c internalapi.ImageManagerService, imageName string, po
216
217
}
217
218
218
219
// 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 ) {
221
221
for _ , imageName := range imageList {
222
222
ids = append (ids , framework .PullPublicImage (c , imageName , podConfig ))
223
223
}
@@ -243,17 +243,3 @@ func removeImage(c internalapi.ImageManagerService, imageName string) {
243
243
framework .ExpectNoError (err , "failed to remove image: %v" , err )
244
244
}
245
245
}
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