runtime

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

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

func (*CallbackExecutor) Exec

func (c *CallbackExecutor) Exec(cmd string, args ...string) ([]byte, error)

Exec forwards invocation to the callback

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

type ExecCallback func(cmd string, args ...string) ([]byte, error)

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

func DefaultExecutor

func DefaultExecutor() Executor

DefaultExecutor returns a default executor

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

func (*FakeLock) Acquire added in v0.3.3

func (p *FakeLock) Acquire() (bool, error)

Acquire implements Acquire method from Lock interface

func (*FakeLock) Owner added in v0.3.8

func (p *FakeLock) Owner() int

Owner implements Owner method from Lock interface

func (*FakeLock) Release added in v0.3.3

func (p *FakeLock) Release() error

Release implements Release method from Lock interface

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

func (*FakeProfiler) Start added in v0.3.3

func (p *FakeProfiler) Start(profiler.Config) (io.Closer, error)

Start updates the FakeProfiler to registers it was started

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

func NewFileLock(path string) Lock

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

Directories

Path Synopsis
Package profiler offers functions to profile the execution of a process using go's built-in profiling tools
Package profiler offers functions to profile the execution of a process using go's built-in profiling tools

Jump to

Keyboard shortcuts

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