testingexec

package
Version: v0.0.0-...-99ec85e Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: Apache-2.0 Imports: 4 Imported by: 38

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 a slice of FakeCommandAction be
	// populated before calling Command(). This makes the fakeexec (and subsequent
	// calls to Run() or CombinedOutput() always return success and there is no
	// ability to set their output.
	DisableScripts bool
}

FakeExec is a simple scripted Interface type.

func (*FakeExec) Command

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

Command is to track the commands that are executed

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

Source Files

Jump to

Keyboard shortcuts

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