Skip to content

Commit

Permalink
Fix EntryForRegistry code coverage randomization
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Mar 25, 2024
1 parent 1456103 commit a6e6444
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"net/url"
"os"
"slices"
"strings"
"sync"

Expand Down Expand Up @@ -137,8 +138,13 @@ func (c dockerAuthConfigWrapper) EntryForRegistry(host string) (ociauth.ConfigEn
if entry, err := c.Config.EntryForRegistry(host); err == nil && entry != zero {
return entry, err
} else if dockerHubHosts[host] {
// 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)")
for dockerHubHost := range dockerHubHosts {
// 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)
keys := make([]string, 0, len(dockerHubHosts))
for k := range dockerHubHosts {
keys = append(keys, k)
}
slices.Sort(keys)
for _, dockerHubHost := range keys {
if dockerHubHost == "" {
continue
}
Expand Down

0 comments on commit a6e6444

Please sign in to comment.