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

testenv

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package testenv starts in-process protocol servers for tests: an S3 fake over HTTP and an SSH server with a read-only SFTP subsystem. Synthetic data only; nothing here is used outside tests.

Index

Constants

This section is empty.

Variables

View Source
var ClientKeys = []string{"consoles", "console", "sources", "plugins", "refusal"}

ClientKeys are the keys the CLI and MCP outputs add around the wire's values: the MCP structured outputs and the CLI's JSON refusal.

Functions

func BuildPlugin

func BuildPlugin(t testing.TB, name string) []byte

BuildPlugin builds sandbox/testdata/plugins/<name> once per test binary.

func ClientKey

func ClientKey(t testing.TB, passphrase []byte) ([]byte, ssh.PublicKey)

ClientKey generates an ed25519 client key: its OpenSSH PEM, encrypted with passphrase when not empty, and its public key.

func Install

func Install(t testing.TB, s plugin.Store, qualified string, bin []byte, question string, timeoutS int) plugin.LockEntry

Install installs bin as the plugin qualified (marketplace/name, or a bare name for the official marketplace) at version 1.0.0.

func Manifest

func Manifest(name, question string, timeoutS int) []byte

Manifest is a valid manifest for a test plugin.

func RepoRoot

func RepoRoot() string

RepoRoot is the lockfile repository root.

func TempStore

func TempStore(t testing.TB) plugin.Store

TempStore is a plugin store the test can remove although installed plugin directories are read-only (0500).

Types

type S3

type S3 struct {
	Endpoint string
	Bucket   string
	// contains filtered or unexported fields
}

S3 is a running S3 fake with one bucket.

func NewS3

func NewS3(t testing.TB, bucket string) *S3

NewS3 starts an S3 fake with bucket.

func (*S3) Put

func (s *S3) Put(t testing.TB, key string, body []byte)

Put stores body at key.

type SFTP

type SFTP struct {
	Host       string
	Port       int
	User       string
	KnownHosts string // a known_hosts file holding the server's key
}

SFTP is a running SFTP server.

func NewSFTP

func NewSFTP(t testing.TB, root string, o SFTPOptions) *SFTP

NewSFTP serves root read-only over SFTP.

type SFTPOptions

type SFTPOptions struct {
	User          string
	Password      string
	AuthorizedKey ssh.PublicKey
}

SFTPOptions are the accepted logins: a password, an authorized key, or both.

type Vocab added in v0.3.0

type Vocab struct {
	Strings  map[string]bool
	Patterns []*regexp.Regexp
	Keys     map[string]bool
}

Vocab is the closed vocabulary of what the agent may read (docs/security-model.md), plus what the agent sent and the fixed texts of the output under test. Tests check every agent-visible output against it as a whitelist: a value, a key or a word outside it fails.

func ClosedVocab added in v0.3.0

func ClosedVocab(extra ...string) Vocab

ClosedVocab is the closed vocabulary plus extra: the agent's own inputs, the test plugins' manifest texts and the fixed texts of the output checked.

func (Vocab) Allowed added in v0.3.0

func (v Vocab) Allowed(s string) bool

Allowed reports whether s is a value of the vocabulary.

func (Vocab) CheckJSON added in v0.3.0

func (v Vocab) CheckJSON(t testing.TB, raw []byte)

CheckJSON fails on anything of a JSON document outside the vocabulary.

func (Vocab) CheckText added in v0.3.0

func (v Vocab) CheckText(t testing.TB, text string)

CheckText fails on any word of text outside the vocabulary.

func (Vocab) JSONOutside added in v0.3.0

func (v Vocab) JSONOutside(raw []byte) []string

JSONOutside lists every key, string or number of one JSON document outside the vocabulary.

func (Vocab) TextOutside added in v0.3.0

func (v Vocab) TextOutside(text string) []string

TextOutside lists every word of text that is not a word of the vocabulary's strings, an id of its patterns, or a small count.

func (Vocab) WithKeys added in v0.3.0

func (v Vocab) WithKeys(keys ...string) Vocab

WithKeys is v allowing keys too.

Directories

Path Synopsis
Package consoletest runs a real lockfile console in the test process: lockkit's console.Run on lockfile's backend, attached to a fake lockhub (hubtest), a local source, plugins built from sandbox/testdata, a scripted human and a real socket in the test's private runtime directory.
Package consoletest runs a real lockfile console in the test process: lockkit's console.Run on lockfile's backend, attached to a fake lockhub (hubtest), a local source, plugins built from sandbox/testdata, a scripted human and a real socket in the test's private runtime directory.

Jump to

Keyboard shortcuts

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