harness

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

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.

func (ConcurrentExecutionStrategy) Execute

Execute implements ExecutionStrategy.

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.

func (LinearExecutionStrategy) Execute

func (LinearExecutionStrategy) Execute(ctx context.Context, runs []*TestRun) error

Execute implements ExecutionStrategy.

type ParallelExecutionStrategy

type ParallelExecutionStrategy struct {
	Limit int
}

ParallelExecutionStrategy executes all test runs concurrently, but limits the number of concurrent runs to the given limit.

func (ParallelExecutionStrategy) Execute

func (p ParallelExecutionStrategy) Execute(ctx context.Context, runs []*TestRun) error

Execute implements ExecutionStrategy.

type Results

type Results struct {
	TotalRuns int
	TotalPass int
	TotalFail int

	Runs map[string]RunResult
}

Results is the full compiled results for a set of test runs.

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.

func (ShuffleExecutionStrategyWrapper) Execute

Execute implements ExecutionStrategy.

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.

func NewTestRun

func NewTestRun(testName string, id string, runner Runnable) *TestRun

func (*TestRun) Cleanup

func (r *TestRun) Cleanup(ctx context.Context) error

func (*TestRun) FullID

func (r *TestRun) FullID() string

func (*TestRun) Result

func (r *TestRun) Result() RunResult

Results returns the results of the test run. Panics if the test run is not done yet.

func (*TestRun) Run

func (r *TestRun) Run(ctx context.Context) (err error)

Run executes the Run function with a self-managed log writer, panic handler, error recording and duration recording. The test error is returned.

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.

func (TimeoutExecutionStrategyWrapper) Execute

Execute implements ExecutionStrategy.

Jump to

Keyboard shortcuts

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