Documentation
¶
Index ¶
- type CleanupCapableT
- type Expectation
- type Failure
- type Level
- type LoggerOption
- type Mode
- type TestLogger
- func (tl *TestLogger) Close()
- func (tl *TestLogger) DPanic(msg string, tags ...tag.Tag)
- func (tl *TestLogger) Debug(msg string, tags ...tag.Tag)
- func (tl *TestLogger) Error(msg string, tags ...tag.Tag)
- func (tl *TestLogger) Expect(level Level, msg string, tags ...tag.Tag) *Expectation
- func (tl *TestLogger) FailOnDPanic(b bool) bool
- func (tl *TestLogger) FailOnError(b bool) bool
- func (tl *TestLogger) FailOnFatal(b bool) bool
- func (tl *TestLogger) Failure() *Failure
- func (tl *TestLogger) Fatal(msg string, tags ...tag.Tag)
- func (tl *TestLogger) Forget(e *Expectation)
- func (tl *TestLogger) Info(msg string, tags ...tag.Tag)
- func (tl *TestLogger) Panic(msg string, tags ...tag.Tag)
- func (tl *TestLogger) T() TestingT
- func (tl *TestLogger) Warn(msg string, tags ...tag.Tag)
- func (tl *TestLogger) With(tags ...tag.Tag) log.Logger
- func (tl *TestLogger) WithTags(tags ...tag.Tag) *TestLogger
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CleanupCapableT ¶
type CleanupCapableT interface {
TestingT
Cleanup(func())
}
CleanupCapable is an interface that allows a test to register cleanup functions. This is /not/ implemented by *rapid.T but is by *testing.T
type Expectation ¶
type Expectation struct {
// contains filtered or unexported fields
}
Expectation represents a log call we expect to happen in tests. For error-level logs, expectations also influence whether the log fails the test based on the logger mode.
func (*Expectation) Forget ¶
func (e *Expectation) Forget()
Forget removes a previously registered expectation. A forgotten expectation will no longer be evaluated when logs are encountered.
func (*Expectation) MatchCount ¶
func (e *Expectation) MatchCount() int64
func (*Expectation) Matched ¶
func (e *Expectation) Matched() bool
type LoggerOption ¶
type LoggerOption func(*TestLogger)
func LogLevel ¶
func LogLevel(level zapcore.Level) LoggerOption
func SetLogLevel ¶
func SetLogLevel(tt CleanupCapableT, level zapcore.Level) LoggerOption
SetLogLevel overrides the temporal test log level during this test.
func WithLogTags ¶
func WithLogTags(tags ...tag.Tag) LoggerOption
WithLogTags adds tags to the logs emitted by the underlying logger
func WithoutCaller ¶ added in v1.29.0
func WithoutCaller() LoggerOption
WithoutCaller stops the TestLogger from logging the caller. This is primarily intended for use when parsing log.Logger-generated logs in files or coming from subprocesses.
func WrapLogger ¶
func WrapLogger(l log.Logger) LoggerOption
type Mode ¶
type Mode string
const ( // FailOnAnyUnexpectedError mode will fail if any unexpected error is encountered, // like an allowlist. Use TestLogger.Expect to add an error to the allowlist. FailOnAnyUnexpectedError Mode = "fail-on-unexpected-errors" // FailOnExpectedErrorOnly mode will only fail if an expected error is encountered, // like a blocklist. Use TestLogger.Expect to add an error to the blocklist. FailOnExpectedErrorOnly = "fail-on-expected-errors" )
type TestLogger ¶
type TestLogger struct {
// contains filtered or unexported fields
}
TestLogger is a log.Logger implementation that logs to the test's logger _but_ will fail the test if log levels _above_ Warn are present
func DontFailOnDPanic ¶ added in v1.29.0
func DontFailOnDPanic(t *TestLogger) *TestLogger
func DontFailOnError ¶ added in v1.29.0
func DontFailOnError(t *TestLogger) *TestLogger
func LogExpectations ¶
func LogExpectations(t *TestLogger) *TestLogger
func NewTestLogger ¶
func NewTestLogger(t TestingT, mode Mode, opts ...LoggerOption) *TestLogger
NewTestLogger creates a new TestLogger that logs to the provided testing.T. Mode controls the behavior of the logger for when an expected or unexpected error is encountered.
func (*TestLogger) Close ¶
func (tl *TestLogger) Close()
Close disallows any further logging, preventing the test framework from complaining about logging post-test.
func (*TestLogger) DPanic ¶
func (tl *TestLogger) DPanic(msg string, tags ...tag.Tag)
DPanic implements log.Logger.
func (*TestLogger) Debug ¶
func (tl *TestLogger) Debug(msg string, tags ...tag.Tag)
Debug implements log.Logger.
func (*TestLogger) Error ¶
func (tl *TestLogger) Error(msg string, tags ...tag.Tag)
Error implements log.Logger.
func (*TestLogger) Expect ¶
func (tl *TestLogger) Expect(level Level, msg string, tags ...tag.Tag) *Expectation
Expect instructs the logger to track matching log calls, as specified by the level, msg, and tag arguments. For error-level logs, depending on the Mode of the test logger, the expectation either acts as an entry in a blocklist (FailOnExpectedErrorOnly) or an allowlist (FailOnAnyUnexpectedError).
func (*TestLogger) FailOnDPanic ¶ added in v1.29.0
func (tl *TestLogger) FailOnDPanic(b bool) bool
FailOnDPanic overrides the behavior of this logger. It returns the previous value so that it can be restored later.
func (*TestLogger) FailOnError ¶ added in v1.29.0
func (tl *TestLogger) FailOnError(b bool) bool
FailOnError overrides the behavior of this logger. It returns the previous value so that it can be restored later.
func (*TestLogger) FailOnFatal ¶ added in v1.29.0
func (tl *TestLogger) FailOnFatal(b bool) bool
FailOnFatal overrides the behavior of this logger. It returns the previous value so that it can be restored later. Note that Fatal-level logs still panic
func (*TestLogger) Failure ¶
func (tl *TestLogger) Failure() *Failure
Failure returns the first Failure that shouldFailTest considered a test-failing log, or nil if no such log has been observed. Sticky: first failure wins.
func (*TestLogger) Fatal ¶
func (tl *TestLogger) Fatal(msg string, tags ...tag.Tag)
Fatal implements log.Logger.
func (*TestLogger) Forget ¶
func (tl *TestLogger) Forget(e *Expectation)
Forget removes a previously registered expectation. A forgotten expectation will no longer be evaluated when logs are encountered.
func (*TestLogger) Info ¶
func (tl *TestLogger) Info(msg string, tags ...tag.Tag)
Info implements log.Logger.
func (*TestLogger) Panic ¶
func (tl *TestLogger) Panic(msg string, tags ...tag.Tag)
Panic implements log.Logger.
func (*TestLogger) T ¶
func (tl *TestLogger) T() TestingT
func (*TestLogger) Warn ¶
func (tl *TestLogger) Warn(msg string, tags ...tag.Tag)
Warn implements log.Logger.
func (*TestLogger) With ¶
func (tl *TestLogger) With(tags ...tag.Tag) log.Logger
With implements log.WithLogger
func (*TestLogger) WithTags ¶
func (tl *TestLogger) WithTags(tags ...tag.Tag) *TestLogger
WithTags gives you a new logger, copying the tags of the source, appending the provided new Tags