runner

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Runner)

Option configures a Runner.

func WithCovermode

func WithCovermode(val string) Option

WithCovermode configures Runner to run tests with `-covermode` flag.

func WithGoBinPath

func WithGoBinPath(goBinPath string) Option

WithGoBinPath configures Runner to use path as go binary for running tests.

By default, `go` is used.

func WithLogger

func WithLogger(logger *log.Logger) Option

WithLogger configures Runner with a logger.

func WithRaceDetection

func WithRaceDetection(enabled bool) Option

WithRaceDetection configures Runner to run tests with `-race` flag.

Note: Enabling race detection will force the covermode to be `atomic`.

func WithRunnerFunc

func WithRunnerFunc(rf command.Runner) Option

WithRunnerFunc configures Runner to use function for running commands.

By default, commands are run with the `os/exec` package, but the runner function can be replaced for testing purposes.

func WithShort

func WithShort(enabled bool) Option

WithShort configures Runner to run tests with `-short` flag.

func WithShuffle

func WithShuffle(val string) Option

WithShuffle configures Runner to run tests with `-shuffle` flag.

func WithTimeout

func WithTimeout(dur time.Duration) Option

WithTimeout configures Runner to use duration for test run timeout.

func WithUUIDFunc

func WithUUIDFunc(uf UUIDFunc) Option

WithUUIDFunc configures Runner to use function for UUID generation.

By default, nanoid.New is used for UUID generation, but function can be replaced for testing purposes.

type Package

type Package struct {
	Time     time.Time `json:"time"`
	Name     string    `json:"name"`
	Pass     bool      `json:"pass"`
	Passed   int       `json:"passed"`
	Skipped  int       `json:"skipped"`
	Failed   int       `json:"failed"`
	Coverage float64   `json:"coverage"`
	Elapsed  float64   `json:"elapsed"`
	Tests    []*Test   `json:"tests"`
	// contains filtered or unexported fields
}

Package is the result of tests in a single package.

type Result

type Result struct {
	UUID     string        `json:"uuid"`
	Error    string        `json:"error"`
	Pass     bool          `json:"pass"`
	Start    time.Time     `json:"start"`
	Duration time.Duration `json:"duration"`
	ExitCode int           `json:"exitCode"`
	Output   []byte        `json:"output"`
	Targets  []string      `json:"targets"`
	Passed   int           `json:"passed"`
	Failed   int           `json:"failed"`
	Skipped  int           `json:"skipped"`
	Tests    int           `json:"tests"`
	Packages []*Package    `json:"packages"`
	// contains filtered or unexported fields
}

Result of a `go test` run.

func (*Result) Close

func (r *Result) Close() error

Close Result.

Deletes the associated coverage directory if it exists.

func (Result) Dir

func (r Result) Dir() string

Dir containing files relevant for the test result.

Directory contains `coverprofile.out` generated by Runner.Run as well as `report.json` which is a code coverage report generated by [coverparser.Parser].

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner runs tests and parses the results.

func New

func New(ctx context.Context, rootDir string, opts ...Option) *Runner

New Runner for running tests.

Runs `go test` on directories for Go source files and parses the output for easy consumption.

The root directory should be the root directory of a Go project with tests.

func (*Runner) PackageForFile

func (r *Runner) PackageForFile(name string) (string, error)

func (*Runner) Run

func (r *Runner) Run(pkgs ...string) (*Result, error)

Run tests for packages.

Runs `go test` on given packages and parses the results.

type Test

type Test struct {
	Time    time.Time `json:"time"`
	Name    string    `json:"name"`
	Package string    `json:"package"`
	Pass    bool      `json:"pass"`
	Skip    bool      `json:"skip"`
	Timeout bool      `json:"timeout"`
	Elapsed float64   `json:"elapsed"`
	Output  string    `json:"output"`
}

Test result of a single test.

type UUIDFunc

type UUIDFunc func() (string, error)

UUIDFunc for generating a UUID for a Result.

By default, nanoid.New is used for UUID generation, but function can be replaced for testing purposes.

Jump to

Keyboard shortcuts

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