process

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package process offers abstractions for the execution of processes It facilitates the testing of components that execute processes by providing mock implementations.

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 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

Jump to

Keyboard shortcuts

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