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@v2 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
- func BuildCatalog(path, version string, txs ...TxFixture) string
- func BuildCatalogCore(coreVersion, path, version string, txs ...TxFixture) string
- func BuildModuleFile(pkg, name, modulePath, catalogImport string) string
- func BuildModuleFileCore(coreVersion, pkg, name, modulePath, catalogImport string) string
- func BuildPlatform(t *testing.T, octx *cue.Context, registryBody string) *platform.Platform
- func NewCatalogRegistry(t *testing.T, fixtures ...CatalogFixture) string
- func NewModuleRegistry(t *testing.T, modules []ModuleFixture, catalogs []CatalogFixture) string
- func UniquePath(t *testing.T, leaf string) string
- type CatalogFixture
- type CtxOwner
- type ModuleFixture
- type TxFixture
Constants ¶
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@v2) still resolves from the public registry / warm workspace cache.
const ContractAPIVersion = "v1"
ContractAPIVersion is the contract level every generated v2 fixture primitive declares. Core v2 keys contracts by the primitive's own apiVersion (enhancement 0010 D4), not by the catalog's build version.
const PrimitiveMatchKey = "opm.test/primitive"
PrimitiveMatchKey is the matchLabels key every generated v2 fixture primitive authors (valued with the primitive's short name). Mirrors the real catalog's shape: matching identity lives in matchLabels (0010 D36) with a transitional duplicate under metadata.labels.
Variables ¶
This section is empty.
Functions ¶
func BuildCatalog ¶
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). The body shape follows the catalog member shape of the core major derived from [defaultCoreVersion]; use BuildCatalogCore to author against another core version.
func BuildCatalogCore ¶
BuildCatalogCore is BuildCatalog with an explicit core version (full version or bare major), selecting the catalog member shape of that core major: v1-era members carry `version` in metadata and version-keyed contract FQNs; v2 members carry `apiVersion`/`catalogVersion`/authored `fqn` and contract FQNs keyed by ContractAPIVersion (transformer keys stay build-keyed in both). No caller passes an explicit version today, so the v1 branch is exercised only through history; kept for pinned-fixture authors and the next major crossing.
func BuildModuleFile ¶ added in v0.5.0
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. The emitted core import derives its major from [defaultCoreVersion]; use BuildModuleFileCore to pin another core version.
func BuildModuleFileCore ¶
BuildModuleFileCore is BuildModuleFile with an explicit core version (a full version like "v1.0.0-alpha.1" or a bare major like "v1"); the emitted core import derives its major from it, matching the dep the fixture writer declares for the same CoreVersion. No caller passes an explicit version today (pinned-fixture tests hand-author their module text instead); kept for pinned-fixture authors and the next major crossing.
The metadata shape follows the core major: on v2, modulePath is the FULL module path (major suffix included — pass "…/modules/hello@v0") and name MUST be its snake_case leaf; on v1, modulePath is the major-free parent path (v1's metadata semantics).
func BuildPlatform ¶
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 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 ¶
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)
// CoreVersion pins the opmodel.dev/core dependency this catalog's
// cue.mod/module.cue declares — the dep line's major, the emitted core
// import, and the generated body shape all derive from it. Empty defaults
// to defaultCoreVersion (the v2 line); historical tests pin a v1-era
// version explicitly. core still resolves from the public registry / warm
// workspace cache.
CoreVersion string
}
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 ¶
NewCtxOwner wraps ctx as a CueContextOwner.
func (CtxOwner) CueContext ¶
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)
// CoreVersion pins the opmodel.dev/core dependency this module's
// cue.mod/module.cue declares — the dep line's major and the emitted core
// import derive from it. Empty defaults to defaultCoreVersion (the v2
// line); historical tests pin a v1-era version explicitly. core still
// resolves from the public registry / warm workspace cache.
CoreVersion string
}
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 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.