Skip to content

Commit d54fee8

Browse files
authored
Merge pull request #36 from infosiftr/random-maps
Fix `EntryForRegistry` code coverage randomization
2 parents 078126a + a6e6444 commit d54fee8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

registry/client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"net/url"
77
"os"
8+
"slices"
89
"strings"
910
"sync"
1011

@@ -137,8 +138,13 @@ func (c dockerAuthConfigWrapper) EntryForRegistry(host string) (ociauth.ConfigEn
137138
if entry, err := c.Config.EntryForRegistry(host); err == nil && entry != zero {
138139
return entry, err
139140
} else if dockerHubHosts[host] {
140-
// TODO this will iterate in a random order -- maybe that's fine, but maybe we want something more stable? (the new "SortedKeys" iterator that we might get in go1.23? I guess that was rejected, so "slices.Sorted(maps.Keys)")
141-
for dockerHubHost := range dockerHubHosts {
141+
// https://github.com/docker-library/meta-scripts/pull/32#issuecomment-2018950756 (TODO hopefully someday we can replace this with something like `iter.Sorted(maps.Keys(dockerHubHosts))`; https://github.com/golang/go/issues/61900)
142+
keys := make([]string, 0, len(dockerHubHosts))
143+
for k := range dockerHubHosts {
144+
keys = append(keys, k)
145+
}
146+
slices.Sort(keys)
147+
for _, dockerHubHost := range keys {
142148
if dockerHubHost == "" {
143149
continue
144150
}

0 commit comments

Comments
 (0)