Documentation ¶
Index ¶
- func FakeTimeoutError(text string) error
- func MockExecCommandReturns(t *testing.T, stdout, stderr string, retcode int) error
- func TestMockExecHelperProcess(t *testing.T)
- type MockExecutor
- func (e *MockExecutor) ExecuteCommand(command string, arg ...string) error
- func (e *MockExecutor) ExecuteCommandWithCombinedOutput(command string, arg ...string) (string, error)
- func (e *MockExecutor) ExecuteCommandWithEnv(env []string, command string, arg ...string) error
- func (e *MockExecutor) ExecuteCommandWithOutput(command string, arg ...string) (string, error)
- func (e *MockExecutor) ExecuteCommandWithStdin(timeout time.Duration, command string, stdin *string, arg ...string) error
- func (e *MockExecutor) ExecuteCommandWithTimeout(timeout time.Duration, command string, arg ...string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FakeTimeoutError ¶
func MockExecCommandReturns ¶
Mock an executed command with the desired return values. STDERR is returned *before* STDOUT.
This will return an error if the given exit code is nonzero. The error return is the primary benefit of using this method.
In order for this to work in a `*_test.go` file, you MUST import TestMockExecHelperProcess exactly as shown below:
import exectest "github.com/rook/rook/pkg/util/exec/test" // import TestMockExecHelperProcess func TestMockExecHelperProcess(t *testing.T) { exectest.TestMockExecHelperProcess(t) }
Inspired by: https://github.com/golang/go/blob/master/src/os/exec/exec_test.go
func TestMockExecHelperProcess ¶
TestHelperProcess isn't a real test. It's used as a helper process for MockExecCommandReturns to simulate output from a command. Notably, this can return a realistic os/exec error. Inspired by: https://github.com/golang/go/blob/master/src/os/exec/exec_test.go
Types ¶
type MockExecutor ¶
type MockExecutor struct { MockExecuteCommand func(command string, arg ...string) error MockExecuteCommandWithEnv func(env []string, command string, arg ...string) error MockStartExecuteCommand func(command string, arg ...string) (*exec.Cmd, error) MockExecuteCommandWithOutput func(command string, arg ...string) (string, error) MockExecuteCommandWithCombinedOutput func(command string, arg ...string) (string, error) MockExecuteCommandWithTimeout func(timeout time.Duration, command string, arg ...string) (string, error) MockExecuteCommandWithStdin func(timeout time.Duration, command string, stdin *string, arg ...string) error }
MockExecutor mocks all the exec commands
func (*MockExecutor) ExecuteCommand ¶
func (e *MockExecutor) ExecuteCommand(command string, arg ...string) error
ExecuteCommand mocks ExecuteCommand
func (*MockExecutor) ExecuteCommandWithCombinedOutput ¶
func (e *MockExecutor) ExecuteCommandWithCombinedOutput(command string, arg ...string) (string, error)
ExecuteCommandWithCombinedOutput mocks ExecuteCommandWithCombinedOutput
func (*MockExecutor) ExecuteCommandWithEnv ¶
func (e *MockExecutor) ExecuteCommandWithEnv(env []string, command string, arg ...string) error
ExecuteCommandWithEnv mocks ExecuteCommandWithEnv
func (*MockExecutor) ExecuteCommandWithOutput ¶
func (e *MockExecutor) ExecuteCommandWithOutput(command string, arg ...string) (string, error)
ExecuteCommandWithOutput mocks ExecuteCommandWithOutput
func (*MockExecutor) ExecuteCommandWithStdin ¶
func (e *MockExecutor) ExecuteCommandWithStdin(timeout time.Duration, command string, stdin *string, arg ...string) error
ExecuteCommandWithStdin starts a process, provides stdin and wait for its completion with timeout.
func (*MockExecutor) ExecuteCommandWithTimeout ¶
func (e *MockExecutor) ExecuteCommandWithTimeout(timeout time.Duration, command string, arg ...string) (string, error)
ExecuteCommandWithTimeout mocks ExecuteCommandWithTimeout