plugintest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 18 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.

Documentation

Overview

Package plugintest is the golden-test harness for WebAssembly plugin authors. It builds a plugin for wasip1 with the Go toolchain, signs it with a fixed test key, runs it through the scanner's own runtime on a fixture folder and compares the facts with a golden file:

var update = flag.Bool("update", false, "rewrite golden files")

func TestGolden(t *testing.T) {
	p := plugintest.Load(t, ".", plugintest.Manifest(t, "manifest.json"))
	plugintest.Golden(t, "testdata/fixture", "testdata/fixture.golden.json", *update, p)
}

The test key is public and fixed; never trust it outside tests. See https://cernly.dev/how/wasm-plugins/.

Index

Constants

View Source
const (
	SHA         = "0123456789abcdef0123456789abcdef01234567"
	CommittedAt = "2026-10-14T16:02:11Z"
	// ModuleHash replaces a wasm plugin's real hash in goldens: the bytes
	// differ between Go releases, the facts must not.
	ModuleHash = "0000000000000000000000000000000000000000000000000000000000000000"
)

Fixed commit identity for fixture scans outside git.

Variables

This section is empty.

Functions

func Build

func Build(t testing.TB, pkg string) []byte

Build compiles the Go main package pkg (a path relative to the test's folder, or an import path) for GOOS=wasip1 GOARCH=wasm, once per test process.

func Golden

func Golden(t testing.TB, dir, golden string, update bool, ps ...plugin.Plugin)

Golden scans dir with ps and compares with the golden file; update rewrites it. Every plugin must run ok: an error in a fixture is a bug.

func Load

func Load(t testing.TB, pkg string, m sdk.Manifest, lim ...wasm.Limits) plugin.Plugin

Load builds pkg, signs it with m and loads it through the runtime.

func Manifest

func Manifest(t testing.TB, file string) sdk.Manifest

Manifest reads a manifest file (the sha256 is filled in by Sign).

func Scan

func Scan(t testing.TB, dir string, ps ...plugin.Plugin) []byte

Scan scans dir with ps and returns the canonical facts file, wasm hashes replaced by ModuleHash.

func Sign

func Sign(t testing.TB, module []byte, m sdk.Manifest) wasm.Bundle

Sign returns the bundle for module, signed with TestKey.

func TestKey

func TestKey() ed25519.PrivateKey

TestKey is wasm.TestKey: fixed, public, never trusted in production.

func TestTrust

func TestTrust(t testing.TB) *wasm.Trust

TestTrust trusts TestKey and nothing else (no built-in keys).

func ValidScan

func ValidScan(data []byte) error

ValidScan validates a facts file against the published scan schema.

Types

This section is empty.

Jump to

Keyboard shortcuts

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