testingexec

package
v0.0.0-...-6fe5fd8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 66

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitFakeCmd

func InitFakeCmd(fake *FakeCmd, cmd string, args ...string) exec.Cmd

InitFakeCmd is for creating a fake exec.Cmd

Types

type FakeAction

type FakeAction func() ([]byte, []byte, error)

FakeAction is a function type

type FakeCmd

type FakeCmd struct {
	Argv                 []string
	CombinedOutputScript []FakeAction
	CombinedOutputCalls  int
	CombinedOutputLog    [][]string
	OutputScript         []FakeAction
	OutputCalls          int
	OutputLog            [][]string
	RunScript            []FakeAction
	RunCalls             int
	RunLog               [][]string
	Dirs                 []string
	Stdin                io.Reader
	Stdout               io.Writer
	Stderr               io.Writer
	Env                  []string
	StdoutPipeResponse   FakeStdIOPipeResponse
	StderrPipeResponse   FakeStdIOPipeResponse
	WaitResponse         error
	StartResponse        error
	DisableScripts       bool
}

FakeCmd is a simple scripted Cmd type.

func (*FakeCmd) CombinedOutput

func (fake *FakeCmd) CombinedOutput() ([]byte, error)

CombinedOutput returns the output from the command

func (*FakeCmd) Output

func (fake *FakeCmd) Output() ([]byte, error)

Output is the response from the command

func (*FakeCmd) Run

func (fake *FakeCmd) Run() error

Run runs the command

func (*FakeCmd) SetDir

func (fake *FakeCmd) SetDir(dir string)

SetDir sets the directory

func (*FakeCmd) SetEnv

func (fake *FakeCmd) SetEnv(env []string)

SetEnv sets the environment variables

func (*FakeCmd) SetStderr

func (fake *FakeCmd) SetStderr(out io.Writer)

SetStderr sets the stderr

func (*FakeCmd) SetStdin

func (fake *FakeCmd) SetStdin(in io.Reader)

SetStdin sets the stdin

func (*FakeCmd) SetStdout

func (fake *FakeCmd) SetStdout(out io.Writer)

SetStdout sets the stdout

func (*FakeCmd) Start

func (fake *FakeCmd) Start() error

Start mimicks starting the process (in the background) and returns the injected StartResponse

func (*FakeCmd) StderrPipe

func (fake *FakeCmd) StderrPipe() (io.ReadCloser, error)

StderrPipe returns an injected ReadCloser & error (via StderrPipeResponse) to be able to inject an output stream on Stderr

func (*FakeCmd) StdoutPipe

func (fake *FakeCmd) StdoutPipe() (io.ReadCloser, error)

StdoutPipe returns an injected ReadCloser & error (via StdoutPipeResponse) to be able to inject an output stream on Stdout

func (*FakeCmd) Stop

func (fake *FakeCmd) Stop()

Stop is to stop the process

func (*FakeCmd) Wait

func (fake *FakeCmd) Wait() error

Wait mimicks waiting for the process to exit returns the injected WaitResponse

type FakeCommandAction

type FakeCommandAction func(cmd string, args ...string) exec.Cmd

FakeCommandAction is the function to be executed

type FakeExec

type FakeExec struct {
	CommandScript []FakeCommandAction
	CommandCalls  int
	LookPathFunc  func(string) (string, error)
	// ExactOrder enforces that commands are called in the order they are scripted,
	// and with the exact same arguments
	ExactOrder bool
	// DisableScripts removes the requirement that CommandScripts be populated
	// before calling Command(). This makes Command() and subsequent calls to
	// Run() or CombinedOutput() always return success and empty output.
	DisableScripts bool
	// contains filtered or unexported fields
}

FakeExec is a simple scripted Interface type.

func (*FakeExec) Command

func (fake *FakeExec) Command(cmd string, args ...string) exec.Cmd

Command returns the next unexecuted command in CommandScripts. This function is safe for concurrent access as long as the underlying FakeExec struct is not modified during execution.

func (*FakeExec) CommandContext

func (fake *FakeExec) CommandContext(ctx context.Context, cmd string, args ...string) exec.Cmd

CommandContext wraps arguments into exec.Cmd

func (*FakeExec) LookPath

func (fake *FakeExec) LookPath(file string) (string, error)

LookPath is for finding the path of a file

type FakeExitError

type FakeExitError struct {
	Status int
}

FakeExitError is a simple fake ExitError type.

func (FakeExitError) Error

func (fake FakeExitError) Error() string

func (FakeExitError) ExitStatus

func (fake FakeExitError) ExitStatus() int

ExitStatus returns the fake status

func (FakeExitError) Exited

func (fake FakeExitError) Exited() bool

Exited always returns true

func (FakeExitError) String

func (fake FakeExitError) String() string

type FakeStdIOPipeResponse

type FakeStdIOPipeResponse struct {
	ReadCloser io.ReadCloser
	Error      error
}

FakeStdIOPipeResponse holds responses to use as fakes for the StdoutPipe and StderrPipe method calls

Jump to

Keyboard shortcuts

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