Documentation
¶
Overview ¶
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.
Index ¶
- Constants
- func NewHub(t testing.TB) (console.HubOptions, *hubtest.Hub, ed25519.PublicKey)
- func SameUserIsolation(t testing.TB) *console.IsolationEnv
- type Console
- type Options
- type Plugin
- type ScriptIO
- func (s *ScriptIO) Ask(ctx context.Context, prompt string, _ time.Duration) (string, bool)
- func (s *ScriptIO) AskSecret(context.Context, string) ([]byte, error)
- func (s *ScriptIO) Lines() int
- func (s *ScriptIO) Output() string
- func (s *ScriptIO) OutputFrom(n int) string
- func (s *ScriptIO) Println(l string)
- func (s *ScriptIO) Push(answers ...string)
Constants ¶
const HubInstance = "files"
HubInstance is the instance name of the hub NewHub makes.
Variables ¶
This section is empty.
Functions ¶
func NewHub ¶ added in v0.6.0
NewHub is a fake lockhub for one console (instance HubInstance), the options that attach a console to it, and the console's instance key.
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 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
// Hub is the fake lockhub the console is attached to, nil when the
// test gave its own (Options.Hub); HubOptions attach a console to it.
Hub *hubtest.Hub
HubOptions console.HubOptions
// contains filtered or unexported fields
}
Console is a running test console.
func (*Console) ConfigPath ¶ added in v0.5.0
ConfigPath is the console's config file (a test changes the policy on disk, then restarts).
type Options ¶
type Options struct {
// Answers script the human at the console's terminal: the policy
// approval first, then the console's own decisions. Requests are
// decided on the hub (Console.Hub), never here.
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.
Clients func() bool
// Hub attaches the console to this hub; unset, to a fake lockhub of
// its own (Console.Hub). A console is hub-attached only.
Hub console.HubOptions
// Now is the console's clock (hub mode: tickets, decisions, plans);
// nil is time.Now.
Now func() time.Time
}
Options shape a test console.
type Plugin ¶
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 ¶
NewScriptIO answers the prompts with answers, in order.
func (*ScriptIO) OutputFrom ¶
OutputFrom is what was printed from line n on.