sdktest

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 19 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 sdktest builds hermetic Go module worlds for tests of published-SDK handling: a scratch module cache and a file:// module proxy that serve real plugin SDK releases. The releases are derived from the SDK this repository itself is pinned to, so no test needs the network or a particular developer-machine cache, and no test touches the shared module cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Home

func Home(t testing.TB) string

Home returns a TempDir to use as a Go user's HOME, with Go telemetry turned off for it so no telemetry writer touches the directory, in both user-config locations (Linux: <home>/.config, macOS: <home>/Library/Application Support). Callers still point HOME and USERPROFILE at it, and should also set XDG_CONFIG_HOME=<home>/.config and XDG_CACHE_HOME=<home>/.cache so Go's configuration and cache never leave the scratch directory.

func PinnedSDK

func PinnedSDK(t testing.TB) string

PinnedSDK returns the extracted directory of the plugin SDK release this repository is pinned to, from the ambient module cache.

func TempDir

func TempDir(t testing.TB) string

TempDir returns a private directory a Go command may write into. Unlike t.TempDir it is removed robustly: the Go command extracts module caches read-only, and a late writer (a flushing Go telemetry or cache writer) can create an entry while the removal scans, which makes a plain RemoveAll end in ENOTEMPTY on the top directory. The cleanup makes the whole tree writable and retries the removal for a bounded time; only a directory that survives every retry fails the test. It is registered at creation, so it runs after the cleanups registered later (LIFO) that still need the files.

Types

type Release

type Release struct {
	Module    string
	Version   string
	ModuleSum string
	GoModSum  string
}

Release is one served module version and the checksums go.sum records for it.

func (Release) Published

func (r Release) Published() devsdk.Published

Published returns the release as a published SDK tuple.

type World

type World struct {
	Root     string
	Proxy    string
	ModCache string
	// contains filtered or unexported fields
}

World is a scratch module cache plus a file:// module proxy.

func New

func New(t testing.TB) *World

New creates an empty world. Its root is a TempDir, so the read-only module cache the Go command extracts is made writable and removed when the test ends.

func (*World) Commands

func (w *World) Commands() [][]string

Commands returns every Go command the world's runner has been asked to run.

func (*World) Consumer

func (w *World) Consumer(name string, releases ...Release) string

Consumer writes a tiny consumer module that imports a dependency-light real SDK package, requiring the given releases, with a go.sum that records exactly their checksums. It returns the module root.

func (*World) Download

func (w *World) Download(consumer string, release Release)

Download extracts the release into the world's module cache the way a real download would, so tests can tamper with the extracted bytes.

func (*World) Environment

func (w *World) Environment() []string

Environment is the environment of every Go command run inside the world: the scratch cache and proxy, no checksum database, no private-module patterns and no Go environment file. GOFLAGS carries -modcacherw like the e2e harness.

func (*World) Extracted

func (w *World) Extracted(release Release) string

Extracted returns where the world's module cache extracts a module version.

func (*World) Policy

func (w *World) Policy(releases ...Release) devsdk.Policy

Policy is the production release policy extended with the world's served SDK releases as reviewed rows: the compiled-in floor and the production rules, with the synthetic releases a test publishes known to it. The floor release a world serves is the real pinned release, so it needs no row (passing it is allowed); every other served SDK version does. Releases of other modules are ignored. A release whose version is already reviewed with other checksums is a test bug: the controller's rows cannot be overridden, so Policy fails the test.

func (*World) PublishPinned

func (w *World) PublishPinned(path string) Release

PublishPinned serves a module of this repository's build list at its pinned version, for the dependencies of a consumer that imports real SDK packages.

func (*World) PublishRequiring

func (w *World) PublishRequiring(path, version string, requires ...Release) Release

PublishRequiring serves a tiny module whose go.mod requires the given releases: a dependency that makes the module graph select another SDK version than its consumer requires directly. The module declares go 1.16, whose unpruned module graph is loaded in full. The last element of path must be a valid package name.

func (*World) PublishSDK

func (w *World) PublishSDK(version string, mutate func(tree string)) Release

PublishSDK serves the plugin SDK at version, built from the pinned SDK tree. mutate, when given, edits a scratch copy of the tree first, which is how tests make releases that lack the isolation capability.

func (*World) Runner

func (w *World) Runner() devsdk.Runner

Runner returns a devsdk.Runner that runs go under the world's environment, appended after the ambient one like a production owned runner, and records every command. A failed command's error carries its combined output.

func (*World) Write

func (w *World) Write(directory, name, content string)

Write writes one file below directory.

Jump to

Keyboard shortcuts

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