zaptest

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package zaptest provides a variety of helpers for testing log output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger added in v1.8.0

func NewLogger(t TestingT, opts ...LoggerOption) *zap.Logger

NewLogger builds a new Logger that logs all messages to the given testing.TB.

logger := zaptest.NewLogger(t)

Use this with a *testing.T or *testing.B to get logs which get printed only if a test fails or if you ran go test -v.

The returned logger defaults to logging debug level messages and above. This may be changd by passing a zaptest.Level during construction.

logger := zaptest.NewLogger(t, zaptest.Level(zap.WarnLevel))

func Sleep deprecated

func Sleep(base time.Duration)

Sleep scales the sleep duration by $TEST_TIMEOUT_SCALE.

Deprecated: This function is intended for internal testing and shouldn't be used outside zap itself. It was introduced before Go supported internal packages.

func Timeout deprecated

func Timeout(base time.Duration) time.Duration

Timeout scales the provided duration by $TEST_TIMEOUT_SCALE.

Deprecated: This function is intended for internal testing and shouldn't be used outside zap itself. It was introduced before Go supported internal packages.

Types

type Buffer

type Buffer = ztest.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.

type Discarder

type Discarder = ztest.Discarder

A Discarder sends all writes to ioutil.Discard.

type FailWriter

type FailWriter = ztest.FailWriter

FailWriter is a WriteSyncer that always returns an error on writes.

type LoggerOption added in v1.8.0

type LoggerOption interface {
	// contains filtered or unexported methods
}

LoggerOption configures the test logger built by NewLogger.

func Level added in v1.8.0

func Level(enab zapcore.LevelEnabler) LoggerOption

Level controls which messages are logged by a test Logger built by NewLogger.

type ShortWriter

type ShortWriter = ztest.ShortWriter

ShortWriter is a WriteSyncer whose write method never returns an error, but always reports that it wrote one byte less than the input slice's length (thus, a "short write").

type Syncer

type Syncer = ztest.Syncer

A Syncer is a spy for the Sync portion of zapcore.WriteSyncer.

type TestingT added in v1.8.0

type TestingT interface {
	// Logs the given message without failing the test.
	Logf(string, ...interface{})

	// Logs the given message and marks the test as failed.
	Errorf(string, ...interface{})

	// Marks the test as failed.
	Fail()

	// Returns true if the test has been marked as failed.
	Failed() bool

	// Returns the name of the test.
	Name() string

	// Marks the test as failed and stops execution of that test.
	FailNow()
}

TestingT is a subset of the API provided by all *testing.T and *testing.B objects.

Directories

Path Synopsis
Package observer provides a zapcore.Core that keeps an in-memory, encoding-agnostic repesentation of log entries.
Package observer provides a zapcore.Core that keeps an in-memory, encoding-agnostic repesentation of log entries.

Jump to

Keyboard shortcuts

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