shelltest

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package shelltest provides a fake shell.Runner and an in-memory shell.Store so backends can be tested without touching the real system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exit

func Exit(c shell.Cmd, code int) error

Exit returns an error that shell.ExitCode reports as code.

Types

type Fake

type Fake struct {

	// Outputs maps a command string or program name to its stdout.
	Outputs map[string]string
	// Errors maps a command string or program name to the error it returns.
	Errors map[string]error
	// Missing lists programs LookPath reports as not installed.
	Missing map[string]bool
	// Names maps a PID to what ProcessName reports; absent PIDs report "".
	Names map[int]string
	// Identities overrides what ProcessIdentity reports for a PID; "" means
	// the process is gone. Without an entry, a PID this fake started
	// reports "fake-<pid>" and any other PID reports "".
	Identities map[int]string
	// Effects maps a program name to a side effect performed by a successful
	// Run, so a fake behaves like the real tool (e.g. ffmpeg writing its
	// output file).
	Effects map[string]func(c shell.Cmd) error

	Calls   []shell.Cmd // every Run, Output and Start, in order
	Started []shell.Cmd // successful Start calls only
	Procs   []Proc      // successful Start calls, with the PID each returned
	Killed  []int       // KillGroup calls
	// contains filtered or unexported fields
}

Fake records every command and answers from scripted responses. Responses are looked up by the full command string (Cmd.String()) first, then by program name.

func New

func New() *Fake

New returns an empty Fake: every command succeeds with no output and every program is installed.

func (*Fake) Commands

func (f *Fake) Commands() []string

Commands returns the string form of every recorded call.

func (*Fake) Count

func (f *Fake) Count(cmd string) int

Count returns how many recorded calls render as cmd.

func (*Fake) KillGroup

func (f *Fake) KillGroup(pid int)

func (*Fake) LookPath

func (f *Fake) LookPath(program string) error

func (*Fake) Output

func (f *Fake) Output(c shell.Cmd) (string, error)

func (*Fake) ProcessIdentity

func (f *Fake) ProcessIdentity(pid int) string

func (*Fake) ProcessName

func (f *Fake) ProcessName(pid int) string

func (*Fake) Ran

func (f *Fake) Ran(cmd string) bool

Ran reports whether cmd was called at least once.

func (*Fake) Reset

func (f *Fake) Reset()

Reset forgets recorded calls, keeping the scripted responses. Processes started before keep their identities, as real ones would keep running.

func (*Fake) Run

func (f *Fake) Run(c shell.Cmd) error

func (*Fake) Start

func (f *Fake) Start(c shell.Cmd) (int, error)

type Proc

type Proc struct {
	PID  int
	Cmd  shell.Cmd
	Call int // index of the Start in Calls
}

Proc is a process the fake started.

type Store

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

Store is an in-memory shell.Store (and wallpaper.State).

func NewStore

func NewStore() *Store

func (*Store) Get

func (s *Store) Get(key string) string

func (*Store) Set

func (s *Store) Set(key, value string)

Jump to

Keyboard shortcuts

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