package testingexec
import "k8s.io/utils/exec/testing"
Index ¶
- func InitFakeCmd(fake *FakeCmd, cmd string, args ...string) exec.Cmd
- type FakeAction
- type FakeCmd
- func (fake *FakeCmd) CombinedOutput() ([]byte, error)
- func (fake *FakeCmd) Output() ([]byte, error)
- func (fake *FakeCmd) Run() error
- func (fake *FakeCmd) SetDir(dir string)
- func (fake *FakeCmd) SetEnv(env []string)
- func (fake *FakeCmd) SetStderr(out io.Writer)
- func (fake *FakeCmd) SetStdin(in io.Reader)
- func (fake *FakeCmd) SetStdout(out io.Writer)
- func (fake *FakeCmd) Start() error
- func (fake *FakeCmd) StderrPipe() (io.ReadCloser, error)
- func (fake *FakeCmd) StdoutPipe() (io.ReadCloser, error)
- func (fake *FakeCmd) Stop()
- func (fake *FakeCmd) Wait() error
- type FakeCommandAction
- type FakeExec
- func (fake *FakeExec) Command(cmd string, args ...string) exec.Cmd
- func (fake *FakeExec) CommandContext(_ context.Context, cmd string, args ...string) exec.Cmd
- func (fake *FakeExec) LookPath(file string) (string, error)
- type FakeExitError
- func (fake FakeExitError) Error() string
- func (fake FakeExitError) ExitStatus() int
- func (fake FakeExitError) Exited() bool
- func (fake FakeExitError) String() string
- type FakeStdIOPipeResponse
Functions ¶
func InitFakeCmd ¶
InitFakeCmd is for creating a fake exec.Cmd
Types ¶
type FakeAction ¶
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 ¶
CombinedOutput returns the output from the command
func (*FakeCmd) Output ¶
Output is the response from the command
func (*FakeCmd) Run ¶
Run runs the command
func (*FakeCmd) SetDir ¶
SetDir sets the directory
func (*FakeCmd) SetEnv ¶
SetEnv sets the environment variables
func (*FakeCmd) SetStderr ¶
SetStderr sets the stderr
func (*FakeCmd) SetStdin ¶
SetStdin sets the stdin
func (*FakeCmd) SetStdout ¶
SetStdout sets the stdout
func (*FakeCmd) Start ¶
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 ¶
Wait mimicks waiting for the process to exit returns the injected WaitResponse
type FakeCommandAction ¶
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 ¶
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 ¶
CommandContext wraps arguments into exec.Cmd
func (*FakeExec) LookPath ¶
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 ¶
fake_exec.go
- Version
- v0.0.0-20260319190234-28399d86e0b5 (latest)
- Published
- Mar 19, 2026
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 9 hours ago –
Tools for package owners.