Help us shape the future of Go! Take the 2026 Go Developer Survey

testutil

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package testutil builds what the engine's tests run: wasip1 programs compiled from testdata at test time, OCI image content made from them (both the CNCF wasm artifact form and ordinary tar-layer images), OCI image layouts on disk, and an in-process distribution registry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Gzip

func Gzip(b []byte) []byte

Gzip compresses b.

func Must

func Must[T any](v T, err error) T

Must panics on error; for table setup.

func RepoRoot

func RepoRoot() string

RepoRoot is the module root, found from this file's location.

func Tar

func Tar(entries ...TarEntry) []byte

Tar builds an uncompressed tar archive.

func Wasm

func Wasm(tb testing.TB, name string) []byte

Wasm compiles testdata/wasm/<name> for wasip1/wasm once per process.

func WriteCorpus

func WriteCorpus(t *testing.T, fuzzName string, seeds ...any)

WriteCorpus writes seeds as committed fuzz corpus files under testdata/fuzz/<fuzzName> of the calling package, in the "go test fuzz v1" encoding, when WRITE_FUZZ_CORPUS=1. Each seed is one value ([]byte, string, uint8, uint32, uint64, int) or a Tuple of them. Normal runs skip: the files are then read by `go test` as seeds.

func WriteLayout

func WriteLayout(tb testing.TB, dir string, c *Content)

WriteLayout writes c as an OCI image layout in dir.

Types

type Content

type Content struct {
	Blobs map[image.Digest][]byte
	// Roots maps a ref name to the descriptor it names.
	Roots map[string]image.Descriptor
}

Content is a set of blobs and named roots, servable by a layout or a registry.

func BuildContent

func BuildContent(specs ...ImageSpec) *Content

BuildContent makes the blobs of the given images.

type ImageSpec

type ImageSpec struct {
	// RefName is the org.opencontainers.image.ref.name / registry tag.
	RefName string
	// Module is the wasm binary. In artifact form it is the single layer;
	// otherwise it is placed at ModulePath inside a tar+gzip layer.
	Module []byte
	// Artifact selects the CNCF wasm artifact form.
	Artifact bool
	// ModulePath is where the module goes in a tar image (default
	// /bin/app.wasm); it becomes the entrypoint.
	ModulePath string
	// Files are extra files of the tar image's first layer.
	Files map[string]string
	// Layers are extra raw layers (uncompressed tar), applied after.
	Layers [][]byte
	Cmd    []string
	Env    []string
	// WorkingDir of the config.
	WorkingDir string
	// Index wraps the manifest in an index that also lists a linux/amd64
	// manifest, so selection is exercised.
	Index bool
	// OS overrides the config's os (default wasip1).
	OS string
}

ImageSpec describes one test image.

type Registry

type Registry struct {
	*httptest.Server
	Repo string

	// RequireToken makes every /v2 request demand a Bearer token from /token.
	RequireToken bool
	// LieDigest makes manifest responses carry a wrong Docker-Content-Digest.
	LieDigest bool
	// Corrupt flips a byte of every blob served.
	Corrupt bool

	Requests []string
	Tokens   atomic.Int32
	// contains filtered or unexported fields
}

Registry is a minimal in-process OCI distribution registry serving one Content under one repository, read-only. It implements exactly the pull half of the distribution spec plus the Docker token flow, which is all the engine speaks; go-containerregistry's registry has no token auth, and a test of the token flow needs a server that demands one.

func NewRegistry

func NewRegistry(repo string, c *Content) *Registry

NewRegistry starts a registry; call Close when done.

func (*Registry) Host

func (r *Registry) Host() string

Host is the registry's host:port.

type TarEntry

type TarEntry struct {
	Name string
	Type byte // tar.TypeReg when zero
	Body []byte
	Link string
	Mode int64
}

TarEntry is one entry of a test tar.

type Tuple added in v0.2.0

type Tuple []any

Tuple is one corpus entry of a fuzz target taking several arguments.

Jump to

Keyboard shortcuts

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