...

Package testingexec

import "k8s.io/utils/exec/testing"
Overview
Index

Overview ▾

func InitFakeCmd

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

InitFakeCmd is for creating a fake exec.Cmd

type FakeAction

FakeAction is a function type

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

type FakeCmd

FakeCmd is a simple scripted Cmd type.

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
}

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

FakeCommandAction is the function to be executed

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

type FakeExec

FakeExec is a simple scripted Interface type.

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
}

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

FakeExitError is a simple fake ExitError type.

type FakeExitError struct {
    Status int
}

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

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

type FakeStdIOPipeResponse struct {
    ReadCloser io.ReadCloser
    Error      error
}