Skip to content

Commit

Permalink
internal/registrytest: upload deterministically
Browse files Browse the repository at this point in the history
In order to be able to use registrytest.Upload in tests,
it's useful if it fails in the same way each time, so
avoid the non-deterministic map iteration.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: Ib619eda45b794e2376a2ba0331b092c1739dd16e
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1173806
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
rogpeppe committed Dec 18, 2023
1 parent 7bcfd0b commit c4c064d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/registrytest/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ func AuthHandler(handler http.Handler, cfg *AuthConfig) http.Handler {

func pushContent(ctx context.Context, client *modregistry.Client, mods map[module.Version]*moduleContent) error {
pushed := make(map[module.Version]bool)
// Iterate over modules in deterministic order.
// TODO use maps.Keys when available.
vs := make([]module.Version, 0, len(mods))
for v := range mods {
vs = append(vs, v)
}
module.Sort(vs)
for _, v := range vs {
err := visitDepthFirst(mods, v, func(v module.Version, m *moduleContent) error {
if pushed[v] {
return nil
Expand Down

0 comments on commit c4c064d

Please sign in to comment.