Skip to content

Commit 6c71b2c

Browse files
committed
internal/registrytest: support prefix
This will allow the cue command tests to test against modules stored at an arbitrary prefix in the OCI registry. For #2330. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I82b3a9026774189d8cc38bf0d109ef0e5daa507a Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1170244 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent d5c0745 commit 6c71b2c

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

cue/load/module_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestModuleFetch(t *testing.T) {
1717
Name: "modfetch",
1818
}
1919
test.Run(t, func(t *cuetxtar.Test) {
20-
r, err := registrytest.New(registrytest.TxtarFS(t.Archive))
20+
r, err := registrytest.New(registrytest.TxtarFS(t.Archive), "")
2121
if err != nil {
2222
t.Fatal(err)
2323
}

internal/registrytest/registry.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/url"
1212
"strings"
1313

14+
"cuelabs.dev/go/oci/ociregistry/ocifilter"
1415
"cuelabs.dev/go/oci/ociregistry/ocimem"
1516
"cuelabs.dev/go/oci/ociregistry/ociserver"
1617
"golang.org/x/tools/txtar"
@@ -25,18 +26,21 @@ import (
2526

2627
// New starts a registry instance that serves modules found inside the
2728
// _registry path inside fsys. It serves the OCI registry protocol.
29+
// If prefix is non-empty, all module paths will be prefixed by that,
30+
// separated by a slash (/).
2831
//
2932
// Each module should be inside a directory named path_vers, where
3033
// slashes in path have been replaced with underscores and should
3134
// contain a cue.mod/module.cue file holding the module info.
3235
//
3336
// The Registry should be closed after use.
34-
func New(fsys fs.FS) (*Registry, error) {
37+
func New(fsys fs.FS, prefix string) (*Registry, error) {
3538
r := ocimem.New()
36-
client, err := modregistry.NewClient(r)
39+
client, err := modregistry.NewClient(ocifilter.Sub(r, prefix))
3740
if err != nil {
3841
return nil, fmt.Errorf("cannot make client: %v", err)
3942
}
43+
4044
mods, err := getModules(fsys)
4145
if err != nil {
4246
return nil, fmt.Errorf("invalid modules: %v", err)

internal/registrytest/registry_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"cuelabs.dev/go/oci/ociregistry"
1313
"cuelabs.dev/go/oci/ociregistry/ociclient"
14+
"cuelabs.dev/go/oci/ociregistry/ocifilter"
1415
"golang.org/x/tools/txtar"
1516

1617
"cuelang.org/go/internal/mod/modregistry"
@@ -34,15 +35,15 @@ func TestRegistry(t *testing.T) {
3435
t.Fatal(err)
3536
}
3637
t.Run(strings.TrimSuffix(name, ".txtar"), func(t *testing.T) {
37-
r, err := New(TxtarFS(ar))
38+
r, err := New(TxtarFS(ar), "someprefix/other")
3839
if err != nil {
3940
t.Fatal(err)
4041
}
4142
defer r.Close()
4243
client, err := ociclient.New(r.Host(), &ociclient.Options{
4344
Insecure: true,
4445
})
45-
runTest(t, client, string(ar.Comment), ar)
46+
runTest(t, ocifilter.Sub(client, "someprefix/other"), string(ar.Comment), ar)
4647
})
4748
}
4849
}

0 commit comments

Comments
 (0)