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 ¶
- func Home(t testing.TB) string
- func PinnedSDK(t testing.TB) string
- func TempDir(t testing.TB) string
- type Release
- type World
- func (w *World) Commands() [][]string
- func (w *World) Consumer(name string, releases ...Release) string
- func (w *World) Download(consumer string, release Release)
- func (w *World) Environment() []string
- func (w *World) Extracted(release Release) string
- func (w *World) Policy(releases ...Release) devsdk.Policy
- func (w *World) PublishPinned(path string) Release
- func (w *World) PublishRequiring(path, version string, requires ...Release) Release
- func (w *World) PublishSDK(version string, mutate func(tree string)) Release
- func (w *World) Runner() devsdk.Runner
- func (w *World) Write(directory, name, content string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Home ¶
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 ¶
PinnedSDK returns the extracted directory of the plugin SDK release this repository is pinned to, from the ambient module cache.
func TempDir ¶
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 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 ¶
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 ¶
Commands returns every Go command the world's runner has been asked to run.
func (*World) Consumer ¶
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 ¶
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 ¶
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 ¶
Extracted returns where the world's module cache extracts a module version.
func (*World) 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 ¶
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 ¶
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 ¶
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.