process

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package process offers abstractions for the execution of processes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lock added in v0.1.2

func Lock(path string) (bool, error)

Lock creates a lock file owned by the invoking process. If the lock exists, it checks if a valid lock from a live process other than itself. Returns false if the lockfile is already own by a live process

func Unlock added in v0.1.2

func Unlock(path string) error

Unlock releases the ownership of a lock file. Returns an error if the invoking process is not the current owner or the file does not exists

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 It facilitates the testing of components that execute processes by providing mock implementations.

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