testingx

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Generated contract batches

Use ModuleBatch when several generated designs share the same Loom source and dependency set. Resolve the source through the owning transport's existing resolver, allocate the batch in the parent test, and add cases sequentially. Pass each case's ModulePath + "/gen" to the generator. WriteFile rebases handwritten harness imports; it must never rewrite generated files. Call Check after the case subtests return. A focused go test -run Parent/Case still runs that case's generated contracts.

Each case retains separate packages and test binaries, isolating global flags, service names and protobuf registrations. The parent owns temporary directories, so subtest cleanup cannot remove inputs before validation. One module shares go mod tidy, full go vet ./... and go test -race -count=1 ./.... The test command disables its implicit vet because the explicit vet already ran. A separate go build would repeat compilation. Runtime tests have a 30-second per-binary timeout; compilation is outside that timeout.

An export directory preserves the original module imports and case paths for artifact comparisons. Exported modules are validated separately. Existing transport-specific generate-only switches still skip validation explicitly. Do not batch cases requiring incompatible dependencies or authored external module paths without preserving those contracts.

Retained regression inventory

The consolidation from 6e64a3d885753cceda57ebe206369cddcd0bf525 preserves all 87 generated variants below while reducing module validation runs from 82 to 12.

Test family HTTP variants JSON-RPC variants gRPC variants Contract retained
Selected body 18 18 — Five directions, renamed fields, six additional carriers, optional views; client/server and CLI runtime checks where previously present
Anonymous validation 4 4 — Nullable and enum combinations, valid and invalid wire payloads
Named nullable validation 3 3 — Object, array and map validation
Nullable collection responses 6 — — Nil, empty, populated and invalid response values and problem details
Client member identity 6 — — Naming reservations plus mounted endpoint, group, CLI and streaming bindings
Server member identity 2 — 8 Naming and emitted declaration inventory, compilation, mounted dispatch and authentication
Custom text clients 9 — — Path, query, header and cookie codecs, validation, defaults and CLI conversion
Request body contracts 6 — — Existing six-case body batch and its unchanged harnesses

The HTTP selected-field identity, HTTP client/server member identity and gRPC member-declaration assertions now run in their corresponding generated cases. Their four separate drivers and repeated DSL evaluations were removed; their assertions were retained. Three selected-body compilation drivers per transport became one matrix each. Distinct mapped-field fallback assertions and custom Stringer external-type tests remain separate.

gRPC member cases render service and transport files, without empty consumer-owned response-contract scaffolds. Those placeholder scenario maps were not executed by the previous member tests. The dedicated scaffold tests still render, populate and execute a real response contract.

Validation evidence

Local uncached test executions with warm compiler caches on Go 1.27.3, Darwin/arm64, and LOOM_DIR selecting this checkout:

Same case inventory Parent seconds Batched seconds
HTTP selected bodies, anonymous/named validation, collection responses and client/server members 121.9 29.4
HTTP custom text clients 35.5 9.2
JSON-RPC selected bodies and anonymous/named validation 92.6 27.6
gRPC server members 27.5 7.3

These are development samples, with some concurrent checks, not CI latency predictions or cold-build benchmarks. Timings exclude nested subtest durations from totals. The existing six-case request-body batch is not counted as a new speedup.

Parent test sources loaded through Go's file overlay and the revised tests exported 19 representative cases: all HTTP/JSON-RPC anonymous variants, all HTTP client/server members, and ordinary, authenticated and located-import gRPC members. All 247 generated files matched byte for byte. Normal batches change only their generated import namespaces; harness bodies and DSL inputs remain unchanged. The standalone module headers use the common replaced Loom requirement.

TestModuleBatchContracts executes two real modules in both batch and export modes, checks distinct namespace values, verifies execution after child cleanup, and fails without race instrumentation. An isolated overlay that inverted its value assertion made the generated test and parent suite fail for that assertion. Focused race/shuffle validation covers every migrated matrix and callers of the split render helpers; repository lint is the commit gate. No exhaustive design corpus or proof execution is added to CI.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyTree

func CopyTree(src string, dst string) error

CopyTree copies a directory tree from src to dst.

func PinLocalReplace

func PinLocalReplace(dir string, repoRoot string) error

PinLocalReplace rewrites the copied fixture go.mod to point the github.com/CaliLuke/loom replace directive at repoRoot.

func RepoRoot

func RepoRoot() string

RepoRoot returns the absolute repository root for the current checkout.

func RequireTreeMatches added in v1.2.1

func RequireTreeMatches(t testing.TB, wantDir string, gotDir string)

RequireTreeMatches asserts that gotDir contains exactly the same regular files as wantDir and that each file has identical contents.

func RunCmd

func RunCmd(dir string, name string, args ...string) (string, error)

RunCmd runs a command in dir and returns its combined output.

func ServicePackageImportNames added in v1.10.0

func ServicePackageImportNames(t testing.TB, dir, genpkg string) []string

ServicePackageImportNames returns sorted external import aliases that share a generated Go file with a service or views import identified by genpkg. It skips service/view declarations themselves, blank/dot imports and imports within the application module (the parent of genpkg). Imports in separate files do not share this collision boundary, even if the files belong to the same package.

The controlled transport fixtures using this helper have no authored external custom types. Only under that assumption do these aliases identify framework imports: rendered syntax cannot establish the provenance of arbitrary external imports. Default names use Loom's import-name convention; explicit aliases are preserved. This is representative fixture coverage, not a template inventory.

func ServicePackageShadowNames added in v1.10.0

func ServicePackageShadowNames(t testing.TB, dir, genpkg, marker string) []string

ServicePackageShadowNames returns the identifiers that the generated Go files below dir declare where a service package imported under the same name would not compile, in the packages that import a service or views package, that is a package whose import path is genpkg/<name> or genpkg/<name>/views:

  • the package-level declarations, which conflict with the import;
  • the receivers, parameters, results and locals in scope where a service or views package is used, which would hide it;
  • in the files that do not import a service or views package, the receivers, parameters, results and locals that are the operand of a selector, such as ws in ws.Close(): a generated file keeps an import when a selector of its name remains, so the file would keep the service package import and leave it unused.

It skips the service and views packages themselves. The result is sorted. It omits struct field names, names with upper case letters, which no generated package name has, and every name that contains marker, so that a test design can mark the names it gives to generated code.

Types

type ModuleBatch added in v1.10.0

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

ModuleBatch shares dependency resolution, vet and race-test invocations across generated contracts with the same Loom source and dependencies. Each case retains a separate package namespace and test binary.

func NewModuleBatch added in v1.10.0

func NewModuleBatch(t *testing.T, source, exportDir string) *ModuleBatch

NewModuleBatch creates one temporary module using the already-resolved Loom source. A nonempty exportDir preserves standalone modules at stable case paths for opt-in artifact comparisons; Check then validates each separately.

func (*ModuleBatch) Case added in v1.10.0

func (b *ModuleBatch) Case(t *testing.T, name, originalModule string) *ModuleCase

Case allocates a unique case directory. Names are relative paths; spaces, hyphens and equals signs are normalized for use in Go import paths. Exported cases retain their original names and module paths for byte comparisons. Add cases sequentially and finish their subtests before calling Check.

func (*ModuleBatch) Check added in v1.10.0

func (b *ModuleBatch) Check(t *testing.T)

Check tidies, vets and race-tests every generated package and runtime harness. Failed setup cannot turn a partial batch into a passing result. The bounded test timeout applies to each test binary, not compilation of the batch. A -run filter may leave a batch empty; no commands run in that case. Explicit vet runs all analyzers, so the subsequent test does not repeat vet.

type ModuleCase added in v1.10.0

type ModuleCase struct {
	// Dir is the directory where the caller renders generated files.
	Dir string
	// ModulePath is the import prefix to pass to the generator for this case.
	ModulePath string
	// contains filtered or unexported fields
}

ModuleCase owns the package namespace and handwritten harness of a case.

func (*ModuleCase) WriteFile added in v1.10.0

func (c *ModuleCase) WriteFile(t *testing.T, name, source string)

WriteFile writes a handwritten fixture, rebasing its module imports into the case namespace. Generated files must instead be rendered with ModulePath.

Jump to

Keyboard shortcuts

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