package ztest
import "go.uber.org/zap/internal/ztest"
Package ztest provides low-level helpers for testing log output. These utilities are helpful in zap's own unit tests, but any assertions using them are strongly coupled to a single encoding.
Index ¶
- func Initialize(factor string) func()
- func Sleep(base time.Duration)
- func Timeout(base time.Duration) time.Duration
- type Buffer
- type Discarder
- type FailWriter
- type MockClock
- func NewMockClock() *MockClock
- func (c *MockClock) Add(d time.Duration)
- func (c *MockClock) NewTicker(d time.Duration) *time.Ticker
- func (c *MockClock) Now() time.Time
- type ShortWriter
- type Syncer
Functions ¶
func Initialize ¶
func Initialize(factor string) func()
Initialize checks the environment and alters the timeout scale accordingly. It returns a function to undo the scaling.
func Sleep ¶
Sleep scales the sleep duration by $TEST_TIMEOUT_SCALE.
func Timeout ¶
Timeout scales the provided duration by $TEST_TIMEOUT_SCALE.
Types ¶
type Buffer ¶
Buffer is an implementation of zapcore.WriteSyncer that sends all writes to a bytes.Buffer. It has convenience methods to split the accumulated buffer on newlines.
func (*Buffer) Lines ¶
Lines returns the current buffer contents, split on newlines.
func (*Buffer) Stripped ¶
Stripped returns the current buffer contents with the last trailing newline stripped.
type Discarder ¶
type Discarder struct{ Syncer }
A Discarder sends all writes to io.Discard.
func (*Discarder) Write ¶
Write implements io.Writer.
type FailWriter ¶
type FailWriter struct{ Syncer }
FailWriter is a WriteSyncer that always returns an error on writes.
func (FailWriter) Write ¶
func (w FailWriter) Write(b []byte) (int, error)
Write implements io.Writer.
type MockClock ¶
type MockClock struct {
// contains filtered or unexported fields
}
MockClock is a fake source of time. It implements standard time operations, but allows the user to control the passage of time.
Use the [Add] method to progress time.
func NewMockClock ¶
func NewMockClock() *MockClock
NewMockClock builds a new mock clock using the current actual time as the initial time.
func (*MockClock) Add ¶
Add progresses time by the given duration. Other operations waiting for the time to advance will be resolved if they are within range.
Side effects of operations waiting for the time to advance will take effect on a best-effort basis. Avoid racing with operations that have side effects.
Panics if the duration is negative.
func (*MockClock) NewTicker ¶
NewTicker returns a time.Ticker that ticks at the specified frequency.
As with time.NewTicker, the ticker will drop ticks if the receiver is slow, and the channel is never closed.
Calling Stop on the returned ticker is a no-op. The ticker only runs when the clock is advanced.
func (*MockClock) Now ¶
Now reports the current time.
type ShortWriter ¶
type ShortWriter struct{ Syncer }
ShortWriter is a WriteSyncer whose write method never fails, but nevertheless fails to the last byte of the input.
func (ShortWriter) Write ¶
func (w ShortWriter) Write(b []byte) (int, error)
Write implements io.Writer.
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
A Syncer is a spy for the Sync portion of zapcore.WriteSyncer.
func (*Syncer) Called ¶
Called reports whether the Sync method was called.
func (*Syncer) SetError ¶
SetError sets the error that the Sync method will return.
func (*Syncer) Sync ¶
Sync records that it was called, then returns the user-supplied error (if any).
Source Files ¶
clock.go doc.go timeout.go writer.go
- Version
- v1.27.0 (latest)
- Published
- Feb 20, 2024
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 6 hours ago –
Tools for package owners.