Documentation
¶
Index ¶
- Variables
- type AnyMatcher
- type ArgumentMatcher
- type Commander
- type ExactMatcher
- type Expectation
- type MockCommander
- func (m *MockCommander) CallOrder() []string
- func (m *MockCommander) CombinedOutput(_ context.Context, name string, args []string, _ ...Option) ([]byte, error)
- func (m *MockCommander) Expect(name string, args ...string) *Expectation
- func (m *MockCommander) ExpectWithMatchers(name string, matchers ...ArgumentMatcher) *Expectation
- func (m *MockCommander) Output(_ context.Context, name string, args []string, _ ...Option) ([]byte, []byte, error)
- func (m *MockCommander) Reset()
- func (m *MockCommander) Run(_ context.Context, name string, args []string, _ ...Option) error
- func (m *MockCommander) Start(_ context.Context, name string, args []string, _ ...Option) (Process, error)
- func (m *MockCommander) VerifyExpectations() error
- type Option
- type Options
- type Process
- type RegexMatcher
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrUnexpectedCommand = errors.New("unexpected command") ErrExpectedCommandNotCalled = errors.New("expected command not called") )
Execution errors
View Source
var ( ErrProcessStartFailed = errors.New("process start failed") ErrProcessWaitFailed = errors.New("process wait failed") ErrPipeCreationFailed = errors.New("pipe creation failed") )
Process errors
View Source
var (
ErrCommandFailed = errors.New("command failed")
)
Command execution errors
Functions ¶
This section is empty.
Types ¶
type AnyMatcher ¶
type AnyMatcher struct{}
Any matcher
func (*AnyMatcher) Matches ¶
func (m *AnyMatcher) Matches(_ string) bool
func (*AnyMatcher) String ¶
func (m *AnyMatcher) String() string
type ArgumentMatcher ¶
ArgumentMatcher interface for flexible argument matching
func Any ¶
func Any() ArgumentMatcher
func Regex ¶
func Regex(pattern string) ArgumentMatcher
type Commander ¶
type Commander interface {
// Run executes a command and waits for completion
Run(
ctx context.Context,
name string,
args []string,
opts ...Option,
) error
// Output executes a command and returns stdout, stderr, and error
Output(
ctx context.Context,
name string,
args []string,
opts ...Option,
) (stdout []byte, stderr []byte, err error)
// CombinedOutput executes a command and returns combined stdout+stderr and error
CombinedOutput(
ctx context.Context,
name string,
args []string,
opts ...Option,
) (output []byte, err error)
// Start creates a command that can be controlled manually
Start(
ctx context.Context,
name string,
args []string,
opts ...Option,
) (Process, error)
}
type ExactMatcher ¶
type ExactMatcher struct {
// contains filtered or unexported fields
}
Exact matcher
func (*ExactMatcher) Matches ¶
func (m *ExactMatcher) Matches(arg string) bool
func (*ExactMatcher) String ¶
func (m *ExactMatcher) String() string
type Expectation ¶
type Expectation struct {
Name string
Args []string
Matchers []ArgumentMatcher
Output []byte
Error error
Called bool
}
func (*Expectation) ReturnError ¶
func (e *Expectation) ReturnError(err error) *Expectation
func (*Expectation) ReturnOutput ¶
func (e *Expectation) ReturnOutput(output []byte) *Expectation
Expectation methods
type MockCommander ¶
type MockCommander struct {
// contains filtered or unexported fields
}
MockCommander for testing
func NewMock ¶
func NewMock() *MockCommander
func (*MockCommander) CallOrder ¶
func (m *MockCommander) CallOrder() []string
func (*MockCommander) CombinedOutput ¶
func (*MockCommander) Expect ¶
func (m *MockCommander) Expect( name string, args ...string, ) *Expectation
func (*MockCommander) ExpectWithMatchers ¶
func (m *MockCommander) ExpectWithMatchers( name string, matchers ...ArgumentMatcher, ) *Expectation
func (*MockCommander) Reset ¶
func (m *MockCommander) Reset()
func (*MockCommander) VerifyExpectations ¶
func (m *MockCommander) VerifyExpectations() error
type Process ¶
type Process interface {
Start() error
Wait() error
StdinPipe() (io.WriteCloser, error)
// Starts streaming from the current moment, not from the beginning
// Multiple streams can be active simultaneously (broadcast)
// Pass nil for channels you don't want to listen to
Stream(stdout, stderr chan<- string)
Stop(ctx context.Context) error
Kill(ctx context.Context) error
PID() int
}
type RegexMatcher ¶
type RegexMatcher struct {
// contains filtered or unexported fields
}
Regex matcher
func (*RegexMatcher) Matches ¶
func (m *RegexMatcher) Matches(arg string) bool
func (*RegexMatcher) String ¶
func (m *RegexMatcher) String() string
Click to show internal directories.
Click to hide internal directories.