Skip to content

Commit f892345

Browse files
committed
internal/registrytest: do not assume subdirectory
This will make it easier to have the contents of several registries contained in the same txtar file. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I8a6810efd17bb9afdd325f070e1ab97b533c7ff5 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1170882 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 1e26aa2 commit f892345

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

cmd/cue/cmd/script_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ func TestScript(t *testing.T) {
108108
"GONOSUMDB=*", // GOPROXY is a private proxy
109109
homeEnvName()+"="+home,
110110
)
111-
if info, err := os.Stat(filepath.Join(e.WorkDir, "_registry")); err == nil && info.IsDir() {
111+
registryDir := filepath.Join(e.WorkDir, "_registry")
112+
if info, err := os.Stat(registryDir); err == nil && info.IsDir() {
113+
// There's a _registry directory. Start a fake registry server to serve
114+
// the modules in it.
112115
prefix := ""
113116
if data, err := os.ReadFile(filepath.Join(e.WorkDir, "_registry_prefix")); err == nil {
114117
prefix = strings.TrimSpace(string(data))
115118
}
116-
// There's a _registry directory. Start a fake registry server to serve
117-
// the modules in it.
118-
reg, err := registrytest.New(os.DirFS(e.WorkDir), prefix)
119+
reg, err := registrytest.New(os.DirFS(registryDir), prefix)
119120
if err != nil {
120121
return fmt.Errorf("cannot start test registry server: %v", err)
121122
}

cue/load/module_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package load_test
22

33
import (
44
"fmt"
5+
"io/fs"
56
"testing"
67

78
"cuelabs.dev/go/oci/ociregistry/ociclient"
@@ -17,7 +18,11 @@ func TestModuleFetch(t *testing.T) {
1718
Name: "modfetch",
1819
}
1920
test.Run(t, func(t *cuetxtar.Test) {
20-
r, err := registrytest.New(registrytest.TxtarFS(t.Archive), "")
21+
rfs, err := fs.Sub(registrytest.TxtarFS(t.Archive), "_registry")
22+
if err != nil {
23+
t.Fatal(err)
24+
}
25+
r, err := registrytest.New(rfs, "")
2126
if err != nil {
2227
t.Fatal(err)
2328
}

internal/registrytest/registry.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ type handler struct {
117117
func getModules(fsys fs.FS) (map[module.Version]*moduleContent, error) {
118118
ctx := cuecontext.New()
119119
modules := make(map[string]*moduleContent)
120-
if err := fs.WalkDir(fsys, "_registry", func(path string, d fs.DirEntry, err error) error {
120+
if err := fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
121121
if err != nil {
122-
// If a filesystem has no _registry directory at all,
122+
// If a filesystem has no entries at all,
123123
// return zero modules without an error.
124-
if path == "_registry" && errors.Is(err, fs.ErrNotExist) {
124+
if path == "." && errors.Is(err, fs.ErrNotExist) {
125125
return fs.SkipAll
126126
}
127127
return err

0 commit comments

Comments
 (0)