Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cleanable ¶
type Cleanable interface { Runnable // Cleanup should clean up any lingering resources from the test. Cleanup(ctx context.Context, id string) error }
Cleanable is an optional extension to Runnable that allows for post-test cleanup.
type ConcurrentExecutionStrategy ¶
type ConcurrentExecutionStrategy struct{}
ConcurrentExecutionStrategy executes all test runs concurrently without any regard for parallelism.
type ExecutionStrategy ¶
type ExecutionStrategy interface { // Execute runs the given runs in whatever way the strategy wants. An error // may only be returned if the strategy has a failure itself, not if any of // the runs fail. Execute(ctx context.Context, runs []*TestRun) error }
ExecutionStrategy defines how a TestHarness should execute a set of runs. It essentially defines the concurrency model for a given testing session.
type LinearExecutionStrategy ¶
type LinearExecutionStrategy struct{}
LinearExecutionStrategy executes all test runs in a linear fashion, one after the other.
type ParallelExecutionStrategy ¶
type ParallelExecutionStrategy struct {
Limit int
}
ParallelExecutionStrategy executes all test runs concurrently, but limits the number of concurrent runs to the given limit.
type RunResult ¶
type RunResult struct { FullID string TestName string ID string Logs []byte Error error StartedAt time.Time Duration time.Duration }
RunResult is the result of a single test run.
type Runnable ¶
type Runnable interface { // Run should use the passed context to handle cancellation and deadlines // properly, and should only return once the test has been fully completed // (no lingering goroutines, unless they are cleaned up by the accompanying // cleanup function). // // The test ID (part after the slash) is passed for identification if // necessary, and the provided logs write should be used for writing // whatever may be necessary for debugging the test. Run(ctx context.Context, id string, logs io.Writer) error }
Runnable is a test interface that can be executed by a TestHarness.
type ShuffleExecutionStrategyWrapper ¶
type ShuffleExecutionStrategyWrapper struct {
Inner ExecutionStrategy
}
ShuffleExecutionStrategyWrapper is an ExecutionStrategy that wraps another ExecutionStrategy and shuffles the order of the test runs before executing.
type TestHarness ¶
type TestHarness struct {
// contains filtered or unexported fields
}
TestHarness runs a bunch of registered test runs using the given ExecutionStrategy.
func NewTestHarness ¶
func NewTestHarness(strategy ExecutionStrategy) *TestHarness
NewTestHarness creates a new TestHarness with the given ExecutionStrategy.
func (*TestHarness) AddRun ¶
func (h *TestHarness) AddRun(testName string, id string, runner Runnable) *TestRun
AddRun creates a new *TestRun with the given name, ID and Runnable, adds it to the harness and returns it. Panics if the harness has been started, or a test with the given run.FullID() is already registered.
This is a convenience method that calls NewTestRun() and h.RegisterRun().
func (*TestHarness) Cleanup ¶
func (h *TestHarness) Cleanup(ctx context.Context) (err error)
Cleanup should be called after the test run has finished and results have been collected.
func (*TestHarness) RegisterRun ¶
func (h *TestHarness) RegisterRun(run *TestRun)
RegisterRun registers the given *TestRun with the harness. Panics if the harness has been started, or a test with the given run.FullID() is already registered.
func (*TestHarness) Results ¶
func (h *TestHarness) Results() Results
Results collates the results of all the test runs and returns them.
func (*TestHarness) Run ¶
func (h *TestHarness) Run(ctx context.Context) (err error)
Run runs the registered tests using the given ExecutionStrategy. The provided context can be used to cancel or set a deadline for the test run. Blocks until the tests have finished and returns the test execution error (not individual run errors).
Panics if called more than once.
type TestRun ¶
type TestRun struct {
// contains filtered or unexported fields
}
TestRun is a single test run and it's accompanying state.
type TimeoutExecutionStrategyWrapper ¶
type TimeoutExecutionStrategyWrapper struct { Timeout time.Duration Inner ExecutionStrategy }
TimeoutExecutionStrategyWrapper is an ExecutionStrategy that wraps another ExecutionStrategy and applies a timeout to each test run's context.