tstest

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package tstest provides utilities for use in unit tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixLogs

func FixLogs(t *testing.T)

func PanicOnLog

func PanicOnLog()

PanicOnLog modifies the standard library log package's default output to an io.Writer that panics, to root out code that's not plumbing their logging through explicit tailscale.com/logger.Logf paths.

func ResourceCheck

func ResourceCheck(tb testing.TB)

func UnfixLogs

func UnfixLogs(t *testing.T)

func WaitFor added in v1.8.0

func WaitFor(maxWait time.Duration, try func() error) error

WaitFor retries try for up to maxWait. It returns nil once try returns nil the first time. If maxWait passes without success, it returns try's last error.

Types

type Clock

type Clock struct {
	// Start is the first value returned by Now.
	Start time.Time
	// Step is how much to advance with each Now call.
	Step time.Duration
	// Present is the time that the next Now call will receive.
	Present time.Time

	sync.Mutex
}

Clock is a testing clock that advances every time its Now method is called, beginning at Start.

The zero value starts virtual time at an arbitrary value recorded in Start on the first call to Now, and time never advances.

func (*Clock) Advance added in v1.0.0

func (c *Clock) Advance(d time.Duration)

func (*Clock) Now

func (c *Clock) Now() time.Time

Now returns the virtual clock's current time, and avances it according to its step configuration.

func (*Clock) Reset

func (c *Clock) Reset()

Reset rewinds the virtual clock to its start time.

type LogLineTracker added in v1.2.0

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

LogLineTracker is a logger that tracks which log format patterns it's seen and can report which expected ones were not seen later.

func NewLogLineTracker added in v1.2.0

func NewLogLineTracker(logf logger.Logf, expectedFormatStrings []string) *LogLineTracker

NewLogLineTracker produces a LogLineTracker wrapping a given logf that tracks whether expectedFormatStrings were seen.

func (*LogLineTracker) Check added in v1.2.0

func (lt *LogLineTracker) Check() []string

Check returns which format strings haven't been logged yet.

func (*LogLineTracker) Close added in v1.4.0

func (lt *LogLineTracker) Close()

Close closes lt. After calling Close, calls to Logf become no-ops.

func (*LogLineTracker) Logf added in v1.2.0

func (lt *LogLineTracker) Logf(format string, args ...interface{})

Logf logs to its underlying logger and also tracks that the given format pattern has been seen.

func (*LogLineTracker) Reset added in v1.8.0

func (lt *LogLineTracker) Reset()

Reset forgets everything that it's seen.

Directories

Path Synopsis
integration
testcontrol
Package testcontrol contains a minimal control plane server for testing purposes.
Package testcontrol contains a minimal control plane server for testing purposes.
Package natlab lets us simulate different types of networks all in-memory without running VMs or requiring root, etc.
Package natlab lets us simulate different types of networks all in-memory without running VMs or requiring root, etc.

Jump to

Keyboard shortcuts

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