ldtest

package
v2.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package ldtest contains a test runner framework that is similar to Go's testing package, but is run as regular Go application code rather than Go tests. It also adds richer capabilities for configuration, logging, and result reporting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleTestLogger

type ConsoleTestLogger struct {
	DebugOutputOnFailure bool
	DebugOutputOnSuccess bool
}

func (ConsoleTestLogger) EndLog

func (c ConsoleTestLogger) EndLog(results Results) error

func (ConsoleTestLogger) TestError

func (c ConsoleTestLogger) TestError(id TestID, err error)

func (ConsoleTestLogger) TestFinished

func (c ConsoleTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput)

func (ConsoleTestLogger) TestSkipped

func (c ConsoleTestLogger) TestSkipped(id TestID, reason string)

func (ConsoleTestLogger) TestStarted

func (c ConsoleTestLogger) TestStarted(id TestID)

type ErrorWithStacktrace

type ErrorWithStacktrace struct {
	Message    string
	Stacktrace []StacktraceInfo
}

func (ErrorWithStacktrace) Error

func (e ErrorWithStacktrace) Error() string

type Filter

type Filter interface {
	Match(id TestID) bool
}

Filter is an object that can determine whether to run a specific test or not.

type FilterFunc

type FilterFunc func(id TestID) bool

func (FilterFunc) Match

func (f FilterFunc) Match(id TestID) bool

type JUnitTestLogger

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

func NewJUnitTestLogger

func NewJUnitTestLogger(
	filePath string,
	serviceInfo serviceinfo.TestServiceInfo,
	filters RegexFilters,
) *JUnitTestLogger

func (*JUnitTestLogger) EndLog

func (j *JUnitTestLogger) EndLog(results Results) error

func (*JUnitTestLogger) TestError

func (j *JUnitTestLogger) TestError(id TestID, err error)

func (*JUnitTestLogger) TestFinished

func (j *JUnitTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput)

func (*JUnitTestLogger) TestSkipped

func (j *JUnitTestLogger) TestSkipped(id TestID, reason string)

func (*JUnitTestLogger) TestStarted

func (j *JUnitTestLogger) TestStarted(id TestID)

type MultiTestLogger

type MultiTestLogger struct {
	Loggers []TestLogger
}

func (*MultiTestLogger) EndLog

func (m *MultiTestLogger) EndLog(results Results) error

func (*MultiTestLogger) TestError

func (m *MultiTestLogger) TestError(id TestID, err error)

func (*MultiTestLogger) TestFinished

func (m *MultiTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput)

func (*MultiTestLogger) TestSkipped

func (m *MultiTestLogger) TestSkipped(id TestID, reason string)

func (*MultiTestLogger) TestStarted

func (m *MultiTestLogger) TestStarted(id TestID)

type RegexFilters

type RegexFilters struct {
	MustMatch    TestIDPatternList
	MustNotMatch TestIDPatternList
}

func (RegexFilters) Describe

func (r RegexFilters) Describe(out io.Writer, supportedCapabilities, allCapabilities []string)

func (RegexFilters) Match

func (r RegexFilters) Match(id TestID) bool

type Results

type Results struct {
	Tests               []TestResult
	Failures            []TestResult
	NonCriticalFailures []TestResult
}

func Run

func Run(
	config TestConfiguration,
	action func(*T),
) Results

Run starts a top-level test scope.

func (Results) OK

func (r Results) OK() bool

type SelfDescribingFilter

type SelfDescribingFilter interface {
	Describe(out io.Writer, supportedCapabilities, importantCapabilities []string) string
}

type StacktraceInfo

type StacktraceInfo struct {
	FileName string
	Package  string
	Function string
	Line     int
}

func (StacktraceInfo) String

func (s StacktraceInfo) String() string

type T

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

T represents a test scope. It is very similar to Go's testing.T type.

func (*T) Capabilities

func (t *T) Capabilities() framework.Capabilities

Capabilities returns the capabilities reported by the test service.

func (*T) Context

func (t *T) Context() interface{}

Context returns the application-defined context value, if any, that was specified in the TestConfiguration.

func (*T) Debug

func (t *T) Debug(message string, args ...interface{})

Debug writes a message to the output for this test scope.

func (*T) DebugLogger

func (t *T) DebugLogger() framework.Logger

DebugLogger returns a Logger instance for writing output for this test scope.

The output that is captured for a test will be passed to TestLogger.TestFinished at the end of the test. The test runner can choose whether to display this or not based on command-line options.

When a test has subtests (created with t.Run), the logger for a subtest starts out with a copy of any output that was already logged for the parent test. During the lifetime of the subtest, any further output that is sent to the parent test's logger will go to the child test's logger instead. This is useful when the parent test scope manages an object such as a mock endpoint that is reused by many subtests.

func (*T) Defer

func (t *T) Defer(cleanupFn func())

Defer schedules a cleanup function which is guaranteed to be called when this test scope exits for any reason. Unlike a Go defer statement, Defer can be used from within helper functions.

func (*T) Errorf

func (t *T) Errorf(format string, args ...interface{})

Errorf reports a test failure. It is equivalent to Go's testing.T.Errorf. It does not cause the test to terminate, but adds the failure message to the output and marks the test as failed.

You will rarely use this method directly; it is part of this type's implementation of the base interfaces testing.T and assert.TestingT, allowing it to be called from assertion helpers.

func (*T) FailNow

func (t *T) FailNow()

FailNow causes the test to immediately terminate and be marked as failed.

You will rarely use this method directly; it is part of this type's implementation of the base interfaces testing.T and assert.TestingT, allowing it to be called from assertion helpers.

func (*T) Helper

func (t *T) Helper()

Helper marks the function that calls it as a test helper that shouldn't appear in stacktraces. Equivalent to Go's testing.T.Helper().

func (*T) ID

func (t *T) ID() TestID

ID returns the full name of the current test.

func (*T) NonCritical

func (t *T) NonCritical(explanation string)

NonCritical indicates that if this test fails, we would like to know about it but we're willing to live with it. It will be shown in the output as a non-critical failure, accompanied by the explanation that is specified here. Non-critical failures do not cause sdk-test-harness to return a non-zero exit code on termination, as regular failures do.

func (*T) RequireCapabilities added in v2.15.0

func (t *T) RequireCapabilities(names ...string)

RequireCapabilities causes the test to be skipped if Capabilities().HasAll(names) returns false.

func (*T) RequireCapability

func (t *T) RequireCapability(name string)

RequireCapability causes the test to be skipped if Capabilities().Has(name) returns false.

func (*T) Run

func (t *T) Run(name string, action func(*T))

Run runs a subtest in its own scope.

This is equivalent to Go's testing.T.Run.

func (*T) Skip

func (t *T) Skip()

Skip causes the test to immediately terminate and be marked as skipped.

func (*T) SkipWithReason

func (t *T) SkipWithReason(reason string)

SkipWithReason is equivalent to Skip but provides a message.

type TestConfiguration

type TestConfiguration struct {
	// Filter is an optional function for determining which tests to run based on their names.
	Filter Filter

	// TestLogger receives status information about each test.
	TestLogger TestLogger

	// Context is an optional value of any type defined by the application which can be accessed from tests.
	Context interface{}

	// Capabilities is a list of strings which are used T.RequireCapability.
	Capabilities []string
}

TestConfiguration contains options for the entire test run.

type TestFailure

type TestFailure struct {
	ID  TestID
	Err error
}

func (TestFailure) Error

func (f TestFailure) Error() string

type TestID

type TestID []string

func (TestID) Plus

func (t TestID) Plus(name string) TestID

func (TestID) String

func (t TestID) String() string

type TestIDPattern

type TestIDPattern []*regexp.Regexp

func ParseTestIDPattern

func ParseTestIDPattern(s string) (TestIDPattern, error)

func (TestIDPattern) Match

func (p TestIDPattern) Match(id TestID, includeParents bool) bool

func (TestIDPattern) String

func (p TestIDPattern) String() string

type TestIDPatternList

type TestIDPatternList []TestIDPattern

func (TestIDPatternList) AnyMatch

func (l TestIDPatternList) AnyMatch(id TestID, includeParents bool) bool

func (TestIDPatternList) IsDefined

func (l TestIDPatternList) IsDefined() bool

func (*TestIDPatternList) Set

func (l *TestIDPatternList) Set(value string) error

Set is called by the command line parser

func (TestIDPatternList) String

func (l TestIDPatternList) String() string

type TestLogger

type TestLogger interface {
	TestStarted(id TestID)
	TestError(id TestID, err error)
	TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput)
	TestSkipped(id TestID, reason string)
	EndLog(results Results) error
}

type TestResult

type TestResult struct {
	TestID      TestID
	Errors      []error
	NonCritical bool
	Explanation string
}

func (TestResult) Failed

func (r TestResult) Failed() bool

Directories

Path Synopsis
Package internal contains test helpers for ldtest.
Package internal contains test helpers for ldtest.

Jump to

Keyboard shortcuts

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