Skip to content

Commit

Permalink
internal/registrytest: do not assume subdirectory
Browse files Browse the repository at this point in the history
This will make it easier to have the contents of several
registries contained in the same txtar file.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I8a6810efd17bb9afdd325f070e1ab97b533c7ff5
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1170882
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
  • Loading branch information
rogpeppe committed Oct 18, 2023
1 parent 1e26aa2 commit f892345
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions cmd/cue/cmd/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ func TestScript(t *testing.T) {
"GONOSUMDB=*", // GOPROXY is a private proxy
homeEnvName()+"="+home,
)
if info, err := os.Stat(filepath.Join(e.WorkDir, "_registry")); err == nil && info.IsDir() {
registryDir := filepath.Join(e.WorkDir, "_registry")
if info, err := os.Stat(registryDir); err == nil && info.IsDir() {
// There's a _registry directory. Start a fake registry server to serve
// the modules in it.
prefix := ""
if data, err := os.ReadFile(filepath.Join(e.WorkDir, "_registry_prefix")); err == nil {
prefix = strings.TrimSpace(string(data))
}
// There's a _registry directory. Start a fake registry server to serve
// the modules in it.
reg, err := registrytest.New(os.DirFS(e.WorkDir), prefix)
reg, err := registrytest.New(os.DirFS(registryDir), prefix)
if err != nil {
return fmt.Errorf("cannot start test registry server: %v", err)
}
Expand Down
7 changes: 6 additions & 1 deletion cue/load/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package load_test

import (
"fmt"
"io/fs"
"testing"

"cuelabs.dev/go/oci/ociregistry/ociclient"
Expand All @@ -17,7 +18,11 @@ func TestModuleFetch(t *testing.T) {
Name: "modfetch",
}
test.Run(t, func(t *cuetxtar.Test) {
r, err := registrytest.New(registrytest.TxtarFS(t.Archive), "")
rfs, err := fs.Sub(registrytest.TxtarFS(t.Archive), "_registry")
if err != nil {
t.Fatal(err)
}
r, err := registrytest.New(rfs, "")
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/registrytest/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ type handler struct {
func getModules(fsys fs.FS) (map[module.Version]*moduleContent, error) {
ctx := cuecontext.New()
modules := make(map[string]*moduleContent)
if err := fs.WalkDir(fsys, "_registry", func(path string, d fs.DirEntry, err error) error {
if err := fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
// If a filesystem has no _registry directory at all,
// If a filesystem has no entries at all,
// return zero modules without an error.
if path == "_registry" && errors.Is(err, fs.ErrNotExist) {
if path == "." && errors.Is(err, fs.ErrNotExist) {
return fs.SkipAll
}
return err
Expand Down

0 comments on commit f892345

Please sign in to comment.