testjson

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDurationAsSeconds

func FormatDurationAsSeconds(d time.Duration, precision int) string

FormatDurationAsSeconds formats a time.Duration as a float.

func PrintSummary

func PrintSummary(out io.Writer, execution *Execution, opts Summary) error

PrintSummary of a test Execution. Prints a section for each summary type followed by a DONE line.

Types

type Action

type Action string

Action of TestEvent

const (
	ActionRun    Action = "run"
	ActionPause  Action = "pause"
	ActionCont   Action = "cont"
	ActionPass   Action = "pass"
	ActionBench  Action = "bench"
	ActionFail   Action = "fail"
	ActionOutput Action = "output"
	ActionSkip   Action = "skip"
)

nolint: unused

type EventFormatter

type EventFormatter func(event TestEvent, output *Execution) (string, error)

EventFormatter is a function which handles an event and returns a string to output for the event.

func NewEventFormatter

func NewEventFormatter(format string) EventFormatter

NewEventFormatter returns a formatter for printing events.

type EventHandler

type EventHandler interface {
	Event(event TestEvent, execution *Execution) error
	Err(text string) error
}

EventHandler is called by ScanTestOutput for each event and write to stderr.

type Execution

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

Execution of one or more test packages

func NewExecution

func NewExecution() *Execution

NewExecution returns a new Execution and records the current time as the time the test execution started.

func ScanTestOutput

func ScanTestOutput(config ScanConfig) (*Execution, error)

ScanTestOutput reads lines from stdout and stderr, creates an Execution, calls the Handler for each event, and returns the Execution.

func (*Execution) Elapsed

func (e *Execution) Elapsed() time.Duration

Elapsed returns the time elapsed since the execution started.

func (*Execution) Errors

func (e *Execution) Errors() []string

Errors returns a list of all the errors.

func (*Execution) Failed

func (e *Execution) Failed() []TestCase

Failed returns a list of all the failed test cases.

func (*Execution) Output

func (e *Execution) Output(pkg, test string) string

Output returns the full test output for a test.

func (*Execution) OutputLines

func (e *Execution) OutputLines(pkg, test string) []string

OutputLines returns the full test output for a test as an array of lines.

func (*Execution) Package

func (e *Execution) Package(name string) *Package

Package returns the Package by name.

func (*Execution) Packages

func (e *Execution) Packages() []string

Packages returns a sorted list of all package names.

func (*Execution) Skipped

func (e *Execution) Skipped() []TestCase

Skipped returns a list of all the skipped test cases.

func (*Execution) Total

func (e *Execution) Total() int

Total returns a count of all test cases.

type Package

type Package struct {
	// TODO: this could be Total()
	Total   int
	Failed  []TestCase
	Skipped []TestCase
	Passed  []TestCase
	// contains filtered or unexported fields
}

Package is the set of TestEvents for a single go package

func (Package) Elapsed

func (p Package) Elapsed() time.Duration

Elapsed returns the sum of the elapsed time for all tests in the package.

func (Package) Output

func (p Package) Output(test string) string

Output returns the full test output for a test.

func (Package) Result

func (p Package) Result() Action

Result returns if the package passed, failed, or was skipped because there were no tests.

func (Package) TestCases

func (p Package) TestCases() []TestCase

TestCases returns all the test cases.

func (Package) TestMainFailed

func (p Package) TestMainFailed() bool

TestMainFailed returns true if the package failed, but there were no tests. This may occur if the package init() or TestMain exited non-zero.

type ScanConfig

type ScanConfig struct {
	Stdout  io.Reader
	Stderr  io.Reader
	Handler EventHandler
}

ScanConfig used by ScanTestOutput

type Summary

type Summary int

Summary enumerates the sections which can be printed by PrintSummary

const (
	SummarizeNone Summary = 1 << (iota * 2)
	SummarizeSkipped
	SummarizeFailed
	SummarizeErrors
	SummarizeAll = SummarizeSkipped | SummarizeFailed | SummarizeErrors
)

nolint: golint

type TestCase

type TestCase struct {
	Package string
	Test    string
	Elapsed time.Duration
}

TestCase stores the name and elapsed time for a test case.

type TestEvent

type TestEvent struct {
	// Time encoded as an RFC3339-format string
	Time    time.Time
	Action  Action
	Package string
	Test    string
	// Elapsed time in seconds
	Elapsed float64
	// Output of test or benchmark
	Output string
	// contains filtered or unexported fields
}

TestEvent is a structure output by go tool test2json and go test -json.

func (TestEvent) Bytes

func (e TestEvent) Bytes() []byte

Bytes returns the serialized JSON bytes that were parsed to create the event.

func (TestEvent) ElapsedFormatted

func (e TestEvent) ElapsedFormatted() string

ElapsedFormatted returns Elapsed formatted in the go test format, ex (0.00s).

func (TestEvent) PackageEvent

func (e TestEvent) PackageEvent() bool

PackageEvent returns true if the event is a package start or end event

Jump to

Keyboard shortcuts

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