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 ¶
- type ConsoleTestLogger
- func (c ConsoleTestLogger) EndLog(results Results) error
- func (c ConsoleTestLogger) TestError(id TestID, err error)
- func (c ConsoleTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput)
- func (c ConsoleTestLogger) TestSkipped(id TestID, reason string)
- func (c ConsoleTestLogger) TestStarted(id TestID)
- type ErrorWithStacktrace
- type Filter
- type FilterFunc
- type JUnitTestLogger
- func (j *JUnitTestLogger) EndLog(results Results) error
- func (j *JUnitTestLogger) TestError(id TestID, err error)
- func (j *JUnitTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput)
- func (j *JUnitTestLogger) TestSkipped(id TestID, reason string)
- func (j *JUnitTestLogger) TestStarted(id TestID)
- type MultiTestLogger
- func (m *MultiTestLogger) EndLog(results Results) error
- func (m *MultiTestLogger) TestError(id TestID, err error)
- func (m *MultiTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput)
- func (m *MultiTestLogger) TestSkipped(id TestID, reason string)
- func (m *MultiTestLogger) TestStarted(id TestID)
- type RegexFilters
- type Results
- type SelfDescribingFilter
- type StacktraceInfo
- type T
- func (t *T) Capabilities() framework.Capabilities
- func (t *T) Context() interface{}
- func (t *T) Debug(message string, args ...interface{})
- func (t *T) DebugLogger() framework.Logger
- func (t *T) Defer(cleanupFn func())
- func (t *T) Errorf(format string, args ...interface{})
- func (t *T) FailNow()
- func (t *T) Helper()
- func (t *T) ID() TestID
- func (t *T) NonCritical(explanation string)
- func (t *T) RequireCapability(name string)
- func (t *T) Run(name string, action func(*T))
- func (t *T) Skip()
- func (t *T) SkipWithReason(reason string)
- type TestConfiguration
- type TestFailure
- type TestID
- type TestIDPattern
- type TestIDPatternList
- type TestLogger
- type TestResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsoleTestLogger ¶
func (ConsoleTestLogger) EndLog ¶ added in v1.0.0
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 ¶ added in v1.1.4
type ErrorWithStacktrace struct { Message string Stacktrace []StacktraceInfo }
func (ErrorWithStacktrace) Error ¶ added in v1.1.4
func (e ErrorWithStacktrace) Error() string
type FilterFunc ¶ added in v1.6.0
func (FilterFunc) Match ¶ added in v1.6.0
func (f FilterFunc) Match(id TestID) bool
type JUnitTestLogger ¶ added in v1.0.0
type JUnitTestLogger struct {
// contains filtered or unexported fields
}
func NewJUnitTestLogger ¶ added in v1.0.0
func NewJUnitTestLogger( filePath string, serviceInfo harness.TestServiceInfo, filters RegexFilters, ) *JUnitTestLogger
func (*JUnitTestLogger) EndLog ¶ added in v1.0.0
func (j *JUnitTestLogger) EndLog(results Results) error
func (*JUnitTestLogger) TestError ¶ added in v1.0.0
func (j *JUnitTestLogger) TestError(id TestID, err error)
func (*JUnitTestLogger) TestFinished ¶ added in v1.0.0
func (j *JUnitTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput)
func (*JUnitTestLogger) TestSkipped ¶ added in v1.0.0
func (j *JUnitTestLogger) TestSkipped(id TestID, reason string)
func (*JUnitTestLogger) TestStarted ¶ added in v1.0.0
func (j *JUnitTestLogger) TestStarted(id TestID)
type MultiTestLogger ¶ added in v1.0.0
type MultiTestLogger struct {
Loggers []TestLogger
}
func (*MultiTestLogger) EndLog ¶ added in v1.0.0
func (m *MultiTestLogger) EndLog(results Results) error
func (*MultiTestLogger) TestError ¶ added in v1.0.0
func (m *MultiTestLogger) TestError(id TestID, err error)
func (*MultiTestLogger) TestFinished ¶ added in v1.0.0
func (m *MultiTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput)
func (*MultiTestLogger) TestSkipped ¶ added in v1.0.0
func (m *MultiTestLogger) TestSkipped(id TestID, reason string)
func (*MultiTestLogger) TestStarted ¶ added in v1.0.0
func (m *MultiTestLogger) TestStarted(id TestID)
type RegexFilters ¶
type RegexFilters struct { MustMatch TestIDPatternList MustNotMatch TestIDPatternList }
func (RegexFilters) Describe ¶ added in v1.6.0
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.
type SelfDescribingFilter ¶ added in v1.6.0
type StacktraceInfo ¶ added in v1.1.4
func (StacktraceInfo) String ¶ added in v1.1.4
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) DebugLogger ¶
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 ¶
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 ¶ added in v1.1.4
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) NonCritical ¶ added in v1.1.0
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) RequireCapability ¶
RequireCapability causes the test to be skipped if HasCapability(name) returns false.
func (*T) Skip ¶
func (t *T) Skip()
Skip causes the test to immediately terminate and be marked as skipped.
func (*T) SkipWithReason ¶
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 by T.HasCapability and T.RequireCapability. Capabilities []string }
TestConfiguration contains options for the entire test run.
type TestFailure ¶
func (TestFailure) Error ¶
func (f TestFailure) Error() string
type TestIDPattern ¶
func ParseTestIDPattern ¶
func ParseTestIDPattern(s string) (TestIDPattern, error)
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 TestResult ¶
func (TestResult) Failed ¶ added in v1.1.0
func (r TestResult) Failed() bool