test

package
v0.0.0-...-331d270 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FakeTimeoutError

func FakeTimeoutError(text string) error

func MockExecCommandReturns

func MockExecCommandReturns(t *testing.T, stdout, stderr string, retcode int) error

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

func TestMockExecHelperProcess(t *testing.T)

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

Jump to

Keyboard shortcuts

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