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 calls each function in whatever way the strategy wants. All // errors returned from the function should be wrapped and returned, but all // given functions must be executed. Run(ctx context.Context, fns []TestFn) ([]error, 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 Results ¶
type Results struct { TotalRuns int `json:"total_runs"` TotalPass int `json:"total_pass"` TotalFail int `json:"total_fail"` Elapsed httpapi.Duration `json:"elapsed"` ElapsedMS int64 `json:"elapsed_ms"` Runs map[string]RunResult `json:"runs"` }
Results is the full compiled results for a set of test runs.
type RunResult ¶
type RunResult struct { FullID string `json:"full_id"` TestName string `json:"test_name"` ID string `json:"id"` Logs string `json:"logs"` Error error `json:"error"` StartedAt time.Time `json:"started_at"` Duration httpapi.Duration `json:"duration"` DurationMS int64 `json:"duration_ms"` }
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 execution strategies.
func NewTestHarness ¶
func NewTestHarness(runStrategy, cleanupStrategy ExecutionStrategy) *TestHarness
NewTestHarness creates a new TestHarness with the given execution strategies.
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.