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

consoletest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package consoletest runs a real lockfile console in the test process: lockkit's console.Run on lockfile's backend, a local source, plugins built from sandbox/testdata, a scripted human and a real socket in the test's private runtime directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SameUserIsolation

func SameUserIsolation(t testing.TB) *console.IsolationEnv

SameUserIsolation lets a test console run in the test's own account (lockkit's AllowSameUser, a test-only switch), with its runtime dir in a fresh short directory under /tmp (socket path length).

Types

type Console

type Console struct {
	IO      *ScriptIO
	Socket  string
	Work    string
	Root    string
	Profile string
	// SharedDir is the socket directory of a Shared console.
	SharedDir string
	// PluginDir is the plugin store (tests tamper with it).
	PluginDir string
	// StartLines is how many lines the console printed before it listened
	// (start-up: isolation, policy review, status).
	StartLines int
	// contains filtered or unexported fields
}

Console is a running test console.

func Start

func Start(t testing.TB, o Options) *Console

Start runs a console serving profile "samples" until the test ends.

func (*Console) Stop

func (c *Console) Stop(t testing.TB)

Stop logs out and waits for the console to end.

type Options

type Options struct {
	// Answers script the human: the policy approval first, then each
	// decision.
	Answers []string
	Plugins []Plugin
	// Files are created in the local source, by key.
	Files map[string]string
	// Profile is extra TOML for the profile "samples" (local source,
	// prefix "invoices/", answer_quantum "1s" unless set here).
	Profile string
	// Path replaces the local source's root (a missing one makes every
	// fetch fail).
	Path    string
	Backend func(*backend.Options)
	// Shared runs the console as in a separated setup: its socket in a
	// shared directory (mode 2750, this process's group) and its own uid
	// faked as another account's, so that this process is served only as
	// a client, and only while Clients (nil: always) allows it.
	Shared  bool
	Clients func() bool
}

Options shape a test console.

type Plugin

type Plugin struct {
	Name, Binary, Question string
	TimeoutS               int
}

Plugin is a test plugin to install: Name is qualified ("test.answer1", "acme/test.answer0"); Binary is the sandbox/testdata/plugins directory (the name's last dot part when empty).

type ScriptIO

type ScriptIO struct {
	// contains filtered or unexported fields
}

ScriptIO answers the console's prompts from a script and records everything the console prints.

func NewScriptIO

func NewScriptIO(answers ...string) *ScriptIO

NewScriptIO answers the prompts with answers, in order.

func (*ScriptIO) Ask

func (s *ScriptIO) Ask(ctx context.Context, prompt string, _ time.Duration) (string, bool)

func (*ScriptIO) AskSecret

func (s *ScriptIO) AskSecret(context.Context, string) ([]byte, error)

func (*ScriptIO) Lines

func (s *ScriptIO) Lines() int

Lines is the number of lines printed so far.

func (*ScriptIO) Output

func (s *ScriptIO) Output() string

Output is everything printed so far, one line each.

func (*ScriptIO) OutputFrom

func (s *ScriptIO) OutputFrom(n int) string

OutputFrom is what was printed from line n on.

func (*ScriptIO) Println

func (s *ScriptIO) Println(l string)

func (*ScriptIO) Push

func (s *ScriptIO) Push(answers ...string)

Push adds answers to the script.

Jump to

Keyboard shortcuts

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