registrytest

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package registrytest provides an in-memory OCI registry harness for tests that need to materialize catalogs without a live registry.

It stands up a modregistrytest registry serving inline `c.#Catalog` fixtures under the CatalogPrefix module path, while opmodel.dev/core@v0 still resolves from the warm workspace cache (via schematest.SetEnv). The CUE_REGISTRY mapping routes the test prefix to the in-process host and leaves every other path on the public registry.

It lives under opm/internal/ so it stays out of the library's public SemVer surface (kernel neutrality) while remaining importable from any opm/* test package. The materialize tests and the kernel integration harness share it so registry semantics never drift between them.

Index

Constants

View Source
const CatalogPrefix = "test.example"

CatalogPrefix is the module-path prefix every in-memory catalog fixture lives under. The CUE_REGISTRY mapping routes this prefix to the in-process registry while opmodel.dev (core@v0) still resolves from the public registry / warm workspace cache.

Variables

This section is empty.

Functions

func BuildCatalog

func BuildCatalog(path, version string, txs ...TxFixture) string

BuildCatalog renders a complete catalog package body (the text after the bare `c.#Catalog` line) for the given module path/version and transformer fixtures. The #Catalog pattern stamps each transformer's metadata.modulePath ("<path>/transformers") and version; this only authors name, description, the required-primitive maps, and the transform output (from TxFixture.Output, defaulting to an empty struct).

func BuildModuleFile added in v0.5.0

func BuildModuleFile(pkg, name, modulePath, catalogImport string) string

BuildModuleFile renders a complete module.cue for a #Module that imports the core schema and (optionally) a single catalog, setting the author-given identity metadata. When catalogImport is non-empty the module imports that major-qualified catalog path and references its metadata under debugValues (an open field), forcing the loader to resolve the catalog as a transitive dependency. pkg is the package clause name.

func BuildPlatform

func BuildPlatform(t *testing.T, octx *cue.Context, registryBody string) *platform.Platform

BuildPlatform builds a concrete *platform.Platform whose #registry contains the given map body (e.g. `{ "test.example/.../cat": {enable: true} }`), validated against core's #Platform. The platform value is built with octx so Materialize can fill catalog values (built with the same context) onto it. CUE_REGISTRY / CUE_CACHE_DIR must already be configured (e.g. by NewCatalogRegistry) so #Platform resolves from the warm workspace cache.

func NewCatalogRegistry

func NewCatalogRegistry(t *testing.T, fixtures ...CatalogFixture) string

NewCatalogRegistry stands up an in-memory OCI registry serving the given catalog fixtures and configures CUE_REGISTRY / CUE_CACHE_DIR for the test scope: the test prefix routes to the in-process host (+insecure), while opmodel.dev/core resolves from the public registry via the warm workspace cache. Returns the CUE_REGISTRY mapping string. The registry is torn down at test end.

Fixture layout follows modregistrytest.New: one directory per (module, version) named "<path with / → _>_v<X.Y.Z>", each holding cue.mod/module.cue (module + language version + the opmodel.dev/core@v0 dep) and catalog.cue (package body importing core and unifying c.#Catalog).

func NewModuleRegistry added in v0.5.0

func NewModuleRegistry(t *testing.T, modules []ModuleFixture, catalogs []CatalogFixture) string

NewModuleRegistry stands up an in-memory OCI registry serving the given module AND catalog fixtures from one host, configuring CUE_REGISTRY / CUE_CACHE_DIR exactly like NewCatalogRegistry. Catalogs published here are resolvable as transitive deps of the modules. Returns the CUE_REGISTRY mapping string.

func UniquePath

func UniquePath(t *testing.T, leaf string) string

UniquePath returns a globally-unique catalog module path for the current test. Uniqueness matters because all tests share the warm workspace CUE module cache (download cache keyed by module path + version): distinct paths prevent one test's fixture content from shadowing another's.

Types

type CatalogFixture

type CatalogFixture struct {
	Path    string // module path without the @major suffix, e.g. "test.example/x/cat"
	Version string // bare SemVer, e.g. "0.1.0"
	Body    string // catalog package body (metadata + #transformers)
}

CatalogFixture is one (path, version) catalog module published into the in-memory registry. Body is the catalog package body that follows the bare `c.#Catalog` line (see BuildCatalog).

type CtxOwner

type CtxOwner struct {
	// contains filtered or unexported fields
}

CtxOwner is a minimal materialize.CueContextOwner wrapping a *cue.Context, so tests can drive Materialize without constructing a full *kernel.Kernel (which would create an import cycle through materialize).

func NewCtxOwner

func NewCtxOwner(ctx *cue.Context) CtxOwner

NewCtxOwner wraps ctx as a CueContextOwner.

func (CtxOwner) CueContext

func (o CtxOwner) CueContext() *cue.Context

CueContext returns the wrapped context.

type ModuleFixture added in v0.5.0

type ModuleFixture struct {
	Path    string            // module path without @major, e.g. "test.example/x/modules/hello"
	Version string            // bare SemVer, e.g. "0.0.2"
	File    string            // full module.cue contents
	Deps    map[string]string // extra deps: "<path>@vN" → bare SemVer (core is added automatically)
}

ModuleFixture is one (path, version) #Module published into the in-memory registry. File is the full module CUE file content (package clause + imports + the c.#Module embed and author-set metadata); Deps lists any module deps BEYOND opmodel.dev/core@v0 that File imports (e.g. a catalog the module references), keyed by major-qualified path → bare SemVer. See BuildModuleFile.

type TxFixture

type TxFixture struct {
	Name      string
	Resources []string
	Traits    []string
	Output    string // optional inline #transform.output literal; "" → "{}"
}

TxFixture describes one transformer to author into a test catalog: its kebab name plus the short names of the resources/traits it requires (used to populate the #matchers reverse index). Output is an optional inline `#transform.output` literal (a CUE struct or list expression); when empty it defaults to an empty struct.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL