Skip to content

Commit

Permalink
internal/registrytest: do not check that dependencies exist
Browse files Browse the repository at this point in the history
Since we've changed the module storage format to avoid
storing dependencies, we don't _need_ to check that
dependencies exist, and it's convenient to be able
to omit them for testing error cases.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I4839cc68388f221b348e96b33f0c16528ec2a980
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1172860
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
rogpeppe committed Nov 30, 2023
1 parent 79033c2 commit 99bdbad
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions internal/registrytest/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,40 +103,16 @@ func AuthHandler(handler http.Handler, cfg *AuthConfig) http.Handler {
}

func pushContent(client *modregistry.Client, mods map[module.Version]*moduleContent) error {
pushed := make(map[module.Version]bool)
for v := range mods {
err := visitDepthFirst(mods, v, func(v module.Version, m *moduleContent) error {
if pushed[v] {
return nil
}
var zipContent bytes.Buffer
if err := m.writeZip(&zipContent); err != nil {
return err
}
if err := client.PutModule(context.Background(), v, bytes.NewReader(zipContent.Bytes()), int64(zipContent.Len())); err != nil {
return err
}
pushed[v] = true
return nil
})
if err != nil {
for v, m := range mods {
var zipContent bytes.Buffer
if err := m.writeZip(&zipContent); err != nil {
return err
}
}
return nil
}

func visitDepthFirst(mods map[module.Version]*moduleContent, v module.Version, f func(module.Version, *moduleContent) error) error {
m := mods[v]
if m == nil {
return fmt.Errorf("no module found for version %v", v)
}
for _, depv := range m.modFile.DepVersions() {
if err := visitDepthFirst(mods, depv, f); err != nil {
if err := client.PutModule(context.Background(), v, bytes.NewReader(zipContent.Bytes()), int64(zipContent.Len())); err != nil {
return err
}
}
return f(v, m)
return nil
}

type Registry struct {
Expand Down

0 comments on commit 99bdbad

Please sign in to comment.