executor

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCommandOutput             = errors.New("command returned no output")
	ErrVersionStrExpectedSemver    = errors.New("expected version string to follow semver format")
	ErrFakeExecutorInvalidArgs     = errors.New("invalid number of args passed to fake executor")
	ErrRepositoryBaseURL           = errors.New("repository base URL undefined, ensure UpdateOptions.BaseURL OR UPDATE_BASE_URL env var is set")
	ErrNoUpdatesApplicable         = errors.New("no updates applicable")
	ErrDmiDecodeRun                = errors.New("error running dmidecode")
	ErrComponentListExpected       = errors.New("expected a list of components to apply updates")
	ErrDeviceInventory             = errors.New("failed to collect device inventory")
	ErrUnsupportedDiskVendor       = errors.New("unsupported disk vendor")
	ErrNoUpdateHandlerForComponent = errors.New("component slug has no update handler declared")
	ErrBinNotExecutable            = errors.New("bin has no executable bit set")
	ErrBinLstat                    = errors.New("failed to run lstat on bin")
	ErrBinLookupPath               = errors.New("failed to lookup bin path")
)

Functions

This section is empty.

Types

type ExecError

type ExecError struct {
	Cmd      string
	Stderr   string
	Stdout   string
	ExitCode int
}

ExecError is returned when the command exits with an error or a non zero exit status

func (*ExecError) Error

func (u *ExecError) Error() string

Error implements the error interface

type Execute

type Execute struct {
	Cmd      string
	Args     []string
	Env      []string
	Stdin    io.Reader
	CheckBin bool
	Quiet    bool
}

An execute instace

func (*Execute) CheckExecutable

func (e *Execute) CheckExecutable() error

CheckExecutable determines if the set Cmd value exists as a file and is an executable.

func (*Execute) ExecWithContext

func (e *Execute) ExecWithContext(ctx context.Context) (result *Result, err error)

ExecWithContext executes the command and returns the Result object

func (*Execute) GetCmd

func (e *Execute) GetCmd() string

GetCmd returns the command with args as a string

func (*Execute) SetArgs

func (e *Execute) SetArgs(a []string)

SetArgs sets the command args

func (*Execute) SetEnv

func (e *Execute) SetEnv(env []string)

SetEnv sets the env variables

func (*Execute) SetStdout

func (e *Execute) SetStdout(_ []byte)

SetStdout doesn't do much, is around for tests

type Executor

type Executor interface {
	ExecWithContext(context.Context) (*Result, error)
	SetArgs([]string)
	SetEnv([]string)
	GetCmd() string
	CheckExecutable() error
	SetStdout([]byte)
}

Executor interface lets us implement dummy executors for tests

func NewExecutor

func NewExecutor(cmd string) Executor

func NewFakeExecutor

func NewFakeExecutor(cmd string) Executor

type FakeExecute

type FakeExecute struct {
	Cmd      string
	Args     []string
	Env      []string
	CheckBin bool
	Stdin    io.Reader
	Stdout   []byte // Set this for the dummy data to be returned
	Stderr   []byte // Set this for the dummy data to be returned
	Quiet    bool
	ExitCode int
}

FakeExecute implements the utils.Executor interface to enable testing

func (*FakeExecute) CheckExecutable

func (e *FakeExecute) CheckExecutable() error

CheckExecutable implements the Executor interface

func (*FakeExecute) CmdPath

func (e *FakeExecute) CmdPath() string

CmdPath returns the absolute path to the executable this means the caller should not have disabled CheckBin.

func (*FakeExecute) DisableBinCheck

func (e *FakeExecute) DisableBinCheck()

func (*FakeExecute) ExecWithContext

func (e *FakeExecute) ExecWithContext(_ context.Context) (*Result, error)

nolint:gocyclo // TODO: break this method up and move into each $util_test.go FakeExecute method returns whatever you want it to return Set e.Stdout and e.Stderr to data to be returned

func (*FakeExecute) GetCmd

func (e *FakeExecute) GetCmd() string

func (*FakeExecute) SetArgs

func (e *FakeExecute) SetArgs(a []string)

func (*FakeExecute) SetEnv

func (e *FakeExecute) SetEnv(env []string)

func (*FakeExecute) SetExitCode

func (e *FakeExecute) SetExitCode(i int)

func (*FakeExecute) SetQuiet

func (e *FakeExecute) SetQuiet()

func (*FakeExecute) SetStderr

func (e *FakeExecute) SetStderr(b []byte)

func (*FakeExecute) SetStdin

func (e *FakeExecute) SetStdin(r io.Reader)

func (*FakeExecute) SetStdout

func (e *FakeExecute) SetStdout(b []byte)

func (*FakeExecute) SetVerbose

func (e *FakeExecute) SetVerbose()

type Result

type Result struct {
	Stdout   []byte
	Stderr   []byte
	ExitCode int
}

The result of a command execution

Jump to

Keyboard shortcuts

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