utils: k8s.io/utils/exec/testing Index | Files

package testingexec

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


Package Files


func InitFakeCmd Uses

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

InitFakeCmd is for creating a fake exec.Cmd

type FakeAction Uses

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

FakeAction is a function type

type FakeCmd Uses

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 Uses

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

CombinedOutput returns the output from the command

func (*FakeCmd) Output Uses

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

Output is the response from the command

func (*FakeCmd) Run Uses

func (fake *FakeCmd) Run() error

Run runs the command

func (*FakeCmd) SetDir Uses

func (fake *FakeCmd) SetDir(dir string)

SetDir sets the directory

func (*FakeCmd) SetEnv Uses

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

SetEnv sets the environment variables

func (*FakeCmd) SetStderr Uses

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

SetStderr sets the stderr

func (*FakeCmd) SetStdin Uses

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

SetStdin sets the stdin

func (*FakeCmd) SetStdout Uses

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

SetStdout sets the stdout

func (*FakeCmd) Start Uses

func (fake *FakeCmd) Start() error

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

func (*FakeCmd) StderrPipe Uses

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 Uses

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 Uses

func (fake *FakeCmd) Stop()

Stop is to stop the process

func (*FakeCmd) Wait Uses

func (fake *FakeCmd) Wait() error

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

type FakeCommandAction Uses

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

FakeCommandAction is the function to be executed

type FakeExec Uses

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 Uses

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

Command is to track the commands that are executed

func (*FakeExec) CommandContext Uses

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

CommandContext wraps arguments into exec.Cmd

func (*FakeExec) LookPath Uses

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

LookPath is for finding the path of a file

type FakeExitError Uses

type FakeExitError struct {
    Status int

FakeExitError is a simple fake ExitError type.

func (FakeExitError) Error Uses

func (fake FakeExitError) Error() string

func (FakeExitError) ExitStatus Uses

func (fake FakeExitError) ExitStatus() int

ExitStatus returns the fake status

func (FakeExitError) Exited Uses

func (fake FakeExitError) Exited() bool

Exited always returns true

func (FakeExitError) String Uses

func (fake FakeExitError) String() string

type FakeStdIOPipeResponse Uses

type FakeStdIOPipeResponse struct {
    ReadCloser io.ReadCloser
    Error      error

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

Package testingexec imports 4 packages (graph) and is imported by 17 packages. Updated 2020-06-08. Refresh now. Tools for package owners.