Documentation ¶
Overview ¶
Package runtime implements functions to interact with the execution runtime
Package runtime abstracts the execution environment of a process
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallbackExecutor ¶
type CallbackExecutor struct { FakeExecutor // contains filtered or unexported fields }
CallbackExecutor is fake process Executor that forwards the invocations to a function that can dynamically return error and output.
func NewCallbackExecutor ¶
func NewCallbackExecutor(callback ExecCallback) *CallbackExecutor
NewCallbackExecutor returns an instance of a CallbackExecutor
type Environment ¶
type Environment interface { // Executor returns a process executor that abstracts os.Exec Executor() Executor // Lock returns an interface for a process lock Lock() Lock // Profiler return an execution profiler Profiler() profiler.Profiler // Vars returns the environment variables Vars() map[string]string // Args returns the arguments passed to the process Args() []string // Signal returns an interface for handling signals Signal() Signals }
Environment abstracts the execution environment of a process. It allows introduction mocks for testing.
func DefaultEnvironment ¶
func DefaultEnvironment() Environment
DefaultEnvironment returns the default execution environment
type ExecCallback ¶
ExecCallback defines a function that can receive the forward of an Exec invocation The function must return the output of the invocation and the execution error, if any
type Executor ¶
type Executor interface { // Exec executes a process and waits for its completion, returning // the combined stdout and stdout Exec(cmd string, args ...string) ([]byte, error) }
Executor offers methods for running processes
type FakeExecutor ¶
type FakeExecutor struct {
// contains filtered or unexported fields
}
FakeExecutor is an instance of a ProcessExecutor that keeps the history of commands for inspection and returns the predefined results. Even when it allows multiple invocations to Exec, it only allows setting one err and output which are returned on each call. If different results are needed for each invocation, CallbackExecutor may a better alternative
func NewFakeExecutor ¶
func NewFakeExecutor(output []byte, err error) *FakeExecutor
NewFakeExecutor creates a new instance of a ProcessExecutor
func (*FakeExecutor) Cmd ¶
func (p *FakeExecutor) Cmd() string
Cmd returns the value of the last command passed to the last invocation
func (*FakeExecutor) CmdHistory ¶
func (p *FakeExecutor) CmdHistory() []string
CmdHistory returns the history of commands executed. If Invocations is 0, returns an empty array
func (*FakeExecutor) Exec ¶
func (p *FakeExecutor) Exec(cmd string, args ...string) ([]byte, error)
Exec mocks the executing of the process according to
func (*FakeExecutor) Invocations ¶
func (p *FakeExecutor) Invocations() int
Invocations returns the number of invocations to the Exec function
func (*FakeExecutor) Invoked ¶
func (p *FakeExecutor) Invoked() bool
Invoked indicates if the Exec command was invoked at least once
func (*FakeExecutor) Reset ¶
func (p *FakeExecutor) Reset()
Reset clears the history of invocations to the FakeProcessExecutor
type FakeLock ¶ added in v0.3.3
type FakeLock struct {
// contains filtered or unexported fields
}
FakeLock implements a Lock for testing
func NewFakeLock ¶ added in v0.3.3
func NewFakeLock() *FakeLock
NewFakeLock returns a default FakeProcess for testing
type FakeProfiler ¶ added in v0.3.3
type FakeProfiler struct {
// contains filtered or unexported fields
}
FakeProfiler is a noop profiler for testing
func NewFakeProfiler ¶ added in v0.3.3
func NewFakeProfiler() *FakeProfiler
NewFakeProfiler creates a new FakeProfiler
func (*FakeProfiler) Close ¶ added in v0.3.3
func (p *FakeProfiler) Close() error
Close updates the FakeProfiler to registers it was stopped operation
type FakeRuntime ¶ added in v0.3.3
type FakeRuntime struct { FakeArgs []string FakeVars map[string]string FakeExecutor *FakeExecutor FakeProfiler *FakeProfiler FakeLock *FakeLock FakeSignal *FakeSignal }
FakeRuntime holds the state of a fake runtime for testing
func NewFakeRuntime ¶ added in v0.3.3
func NewFakeRuntime(args []string, vars map[string]string) *FakeRuntime
NewFakeRuntime creates a default FakeRuntime
func (*FakeRuntime) Args ¶ added in v0.3.3
func (f *FakeRuntime) Args() []string
Args implements Args method from Runtime interface
func (*FakeRuntime) Executor ¶ added in v0.3.3
func (f *FakeRuntime) Executor() Executor
Executor implements Executor method from Runtime interface
func (*FakeRuntime) Lock ¶ added in v0.3.3
func (f *FakeRuntime) Lock() Lock
Lock implements Lock method from Runtime interface
func (*FakeRuntime) Profiler ¶ added in v0.3.3
func (f *FakeRuntime) Profiler() profiler.Profiler
Profiler implements Profiler method from Runtime interface
func (*FakeRuntime) Signal ¶ added in v0.3.3
func (f *FakeRuntime) Signal() Signals
Signal implements Signal method from Runtime interface
func (*FakeRuntime) Vars ¶ added in v0.3.3
func (f *FakeRuntime) Vars() map[string]string
Vars implements Vars method from Runtime interface
type FakeSignal ¶ added in v0.3.3
type FakeSignal struct {
// contains filtered or unexported fields
}
FakeSignal implements a fake signal handling for testing
func NewFakeSignal ¶ added in v0.3.3
func NewFakeSignal() *FakeSignal
NewFakeSignal returns a FakeSignal
func (*FakeSignal) Notify ¶ added in v0.3.3
func (f *FakeSignal) Notify(_ ...os.Signal) <-chan os.Signal
Notify implements Signal's interface Notify method
func (*FakeSignal) Reset ¶ added in v0.3.3
func (f *FakeSignal) Reset(_ ...os.Signal)
Reset implements Signal's interface Reset method. It is noop.
func (*FakeSignal) Send ¶ added in v0.3.3
func (f *FakeSignal) Send(signal os.Signal)
Send sends the given signal to the signal notification channel if the signal was previously specified in a call to Notify
type Lock ¶
type Lock interface { // Acquire tries to acquire an execution lock to prevent concurrent executions. // Returns false if lock is already acquired by another process. Acquire() (bool, error) // Release releases the execution lock Release() error // Owner returns the pid of the current owner. -1 means lock is not currently owned Owner() int }
Lock defines a process lock
func DefaultLock ¶ added in v0.3.3
func DefaultLock() Lock
DefaultLock create a new Lock for the currently running process
func NewFileLock ¶ added in v0.3.3
NewFileLock returns a file lock for the given path
type Signals ¶ added in v0.3.3
type Signals interface { // Notify returns a channel for receiving notifications of the given signals Notify(...os.Signal) <-chan os.Signal // Reset stops receiving signal notifications in this channel. // If no signal is specified, all signals are cleared Reset(...os.Signal) }
Signals define methods for handling signals
func DefaultSignals ¶ added in v0.3.3
func DefaultSignals() Signals
DefaultSignals returns a default signal handler