Documentation
¶
Overview ¶
Package scriptruntest is the runner the suites of scriptrun's kinds share (hooks, scripts, and release): a real scriptrun Engine and its Service over a fresh database, the app's next start over the same history, a fake terminal app that runs each run meant for the user's terminal under /bin/sh (Terminal), and waits for a run's end that look again only when the engine says the runs changed, never on a timer (AwaitShell alone polls, for a shell the engine notes without telling).
It is test support only, built on internal/testutil: only _test.go files may import it, which a repoguard test enforces, so none of it reaches the app.
Index ¶
- Constants
- type Harness
- func (h *Harness) Await(cond func() bool, msgAndArgs ...any)
- func (h *Harness) AwaitShell(id int64)
- func (h *Harness) Ended(id int64) scriptrun.Run
- func (h *Harness) Next(verifiers map[scriptrun.Kind]scriptrun.Verifier) *scriptrun.Engine
- func (h *Harness) Restart(id int64, verifiers map[scriptrun.Kind]scriptrun.Verifier) scriptrun.Run
- type Option
- type Terminal
Constants ¶
const Wait = 30 * time.Second
Wait bounds how long a test waits for a run to end, or for what it awaits.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Harness ¶
type Harness struct {
// DB holds script_runs, LogDir the runs' logs, and Locks the clone locks, which the
// service under test shares with the runner. The next start (Next) runs over the same
// three.
DB *sql.DB
LogDir string
Locks *clonelock.Set
// Engine starts the runs, and Runs reads them back.
Engine *scriptrun.Engine
Runs *scriptrun.Service
// contains filtered or unexported fields
}
Harness is the runner as the app builds it, over a fresh database, a log folder and a set of clone locks of its own, and a home: the Engine the service under test starts its runs with, and the Service that reads them back as the window does. The engine stops every run when the test ends.
func New ¶
New returns a Harness whose runs' folders show under home with ~, and whose engine logs to logger (nil discards).
func (*Harness) Await ¶
Await waits until cond holds, and fails the test with msgAndArgs, and why the wait most likely ran out, when it hasn't within Wait. It looks again each time the engine says the runs changed, so cond must hold once that is told: a run started, its end recorded or refused, its clone let go of, or what its kind's Released did, all of which come before the engine tells it.
func (*Harness) AwaitShell ¶
AwaitShell waits until the engine has seen the shell the terminal runs the run id in: its PID recorded, so the shell's end is read as the run's, with its exit status or without one. A test that ends such a shell, as a user closes the terminal, waits for this first, since a shell that comes and goes unseen reads as a terminal that never ran the command, once the engine's wait for it is up. The engine tells no change as it notes a shell (the window shows no PID, so telling it would only list the runs again), so this wait alone looks again on a timer, every shellPoll, up to Wait, reading the run's record as scriptrun's own tests do.
func (*Harness) Ended ¶
Ended waits for the run id to end and let go of its clone, and returns it as the window reads it. It looks again each time the engine says the runs changed, which it does once a run's end is recorded and the run has let go of its clone, and fails the test when the run hasn't ended within Wait, saying where the run stands and why the wait most likely ran out.
type Option ¶
type Option func(*Harness)
Option sets up a Harness as New builds it.
func WithTerminal ¶
func WithTerminal(term scriptrun.TerminalOpener) Option
WithTerminal has the harness's engines, the next start's included, open the runs in the terminal in term, such as a Terminal. Without it, a run in the terminal fails to start.
type Terminal ¶
type Terminal struct {
// Env is the environment the terminal's shell starts with, beside the test's own and
// what each run exports: the user's environment as a login shell would read it, such
// as a fake tool's entry. Set it before the first run opens.
Env []string
// contains filtered or unexported fields
}
Terminal stands in for the user's terminal app, for the runs a Harness's engine opens there (WithTerminal): it starts each run's command with /bin/sh running testutil.TerminalScript, with no window, and records each run it was asked to open. Close closes it as a user closes the terminal's tab mid-run. A shell still going as the test ends is stopped before the folders its run writes into are removed.
func NewTerminal ¶
NewTerminal returns a Terminal for the test t.
func (*Terminal) Close ¶
Close closes the terminal as a user closes its tab while a run goes on: every shell's process group is hung up (SIGHUP), so the command is cut off where it is and the shell ends without writing the exit status. It returns once every shell has ended.
func (*Terminal) OpenFolder ¶
OpenFolder opens nothing: no test of a run asks for the terminal in its folder.
func (*Terminal) OpenRun ¶
OpenRun starts the run's command in a shell that outlives the call, as a terminal's does.
func (*Terminal) Opened ¶
func (term *Terminal) Opened() []scriptrun.TerminalRun
Opened returns the runs it was asked to open, in order.