tstest

package
v0.0.0-...-ded95ce Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: BSD-3-Clause Imports: 14 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 MinAllocsPerRun

func MinAllocsPerRun(t *testing.T, target uint64, f func()) error

MinAllocsPerRun asserts that f can run with no more than target allocations. It runs f up to 1000 times or 5s, whichever happens first. If f has executed more than target allocations on every run, it returns a non-nil error.

MinAllocsPerRun sets GOMAXPROCS to 1 during its measurement and restores it before returning.

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

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.

func WhileTestRunningLogger

func WhileTestRunningLogger(t testing.TB) logger.Logf

WhileTestRunningLogger returns a logger.Logf that logs to t.Logf until the test finishes, at which point it no longer logs anything.

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

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 advances it according to its step configuration.

func (*Clock) Reset

func (c *Clock) Reset()

Reset rewinds the virtual clock to its start time.

type LogLineTracker

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

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

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

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

func (*LogLineTracker) Close

func (lt *LogLineTracker) Close()

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

func (*LogLineTracker) Logf

func (lt *LogLineTracker) Logf(format string, args ...any)

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

func (*LogLineTracker) Reset

func (lt *LogLineTracker) Reset()

Reset forgets everything that it's seen.

type MemLogger

type MemLogger struct {
	sync.Mutex
	bytes.Buffer
}

MemLogger is a bytes.Buffer with a Logf method for tests that want to log to a buffer.

func (*MemLogger) Logf

func (ml *MemLogger) Logf(format string, args ...any)

func (*MemLogger) String

func (ml *MemLogger) String() string

Directories

Path Synopsis
Package integration contains Tailscale integration tests.
Package integration contains Tailscale integration tests.
testcontrol
Package testcontrol contains a minimal control plane server for testing purposes.
Package testcontrol contains a minimal control plane server for testing purposes.
vms
Package vms does VM-based integration/functional tests by using qemu and a bank of pre-made VM images.
Package vms does VM-based integration/functional tests by using qemu and a bank of pre-made VM images.
Package iosdeps is a just a list of the packages we import on iOS, to let us test that our transitive closure of dependencies on iOS doesn't accidentally grow too large, as we've historically been memory constrained there.
Package iosdeps is a just a list of the packages we import on iOS, to let us test that our transitive closure of dependencies on iOS doesn't accidentally grow too large, as we've historically been memory constrained there.
Package jsdeps is a just a list of the packages we import in the JavaScript/WASM build, to let us test that our transitive closure of dependencies doesn't accidentally grow too large, since binary size is more of a concern.
Package jsdeps is a just a list of the packages we import in the JavaScript/WASM build, to let us test that our transitive closure of dependencies doesn't accidentally grow too large, since binary size is more of a concern.
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