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
- func CompilationCache() wazero.CompilationCache
- func Gzip(b []byte) []byte
- func Must[T any](v T, err error) T
- func RepoRoot() string
- func Tar(entries ...TarEntry) []byte
- func Wasm(tb testing.TB, name string) []byte
- func WasmTags(tb testing.TB, name, tags string) []byte
- func WriteCorpus(t *testing.T, fuzzName string, seeds ...any)
- func WriteLayout(tb testing.TB, dir string, c *Content)
- type Content
- type ImageSpec
- type Registry
- type TarEntry
- type Tuple
Constants ¶
const CompilationCacheEnv = "WCTR_TEST_COMPILATION_CACHE"
CompilationCacheEnv names a directory where the tests keep wazero's machine code, shared by the test processes of every package (they run in parallel; wazero writes each entry to a temporary file and renames it) and, in CI, across runs.
Variables ¶
This section is empty.
Functions ¶
func CompilationCache ¶ added in v0.29.0
func CompilationCache() wazero.CompilationCache
CompilationCache is the process-wide compilation cache tests hand to their executors (wazero.Options.CompilationCache): a guest is compiled once per process, or once per machine when CompilationCacheEnv is set, instead of once per executor. Compiling Go guests is most of what the engine's tests spent under -race.
func RepoRoot ¶
func RepoRoot() string
RepoRoot is the module root, found from this file's location.
func WriteCorpus ¶
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.
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 ¶
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 ¶
NewRegistry starts a registry; call Close when done.