testutil

package
v0.0.0-...-5655933 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Reimport the go-cmp package as the name 'cmp' conflicts with the cmp instruction in the vm.

Copyright 2021 Google Inc. All Rights Reserved. This file is available under the Apache license.

Copyright 2019 Google Inc. All Rights Reserved. This file is available under the Apache license.

Index

Constants

View Source
const RaceDetectorMultiplier = 1.0

Variables

This section is empty.

Functions

func AllowUnexported

func AllowUnexported(types ...interface{}) cmp.Option

func Chdir

func Chdir(tb testing.TB, dir string)

Chdir changes current working directory, and registers a cleanup function to return to the previous directory.

func Diff

func Diff(a, b interface{}, opts ...cmp.Option) string

func DoOrTimeout

func DoOrTimeout(do func() (bool, error), deadline, interval time.Duration) (bool, error)

DoOrTimeout runs a check function every interval until deadline, unless the check returns true. The check should return false otherwise. If the check returns an error the check is immediately failed.

func ExpectExpvarDeltaWithDeadline

func ExpectExpvarDeltaWithDeadline(tb testing.TB, name string, want int64) func()

ExpectExpvarDeltaWithDeadline returns a deferrable function which tests if the expvar metric with name has changed by delta within the given deadline, once the function begins. Before returning, it fetches the original value for comparison.

func ExpectMapExpvarDeltaWithDeadline

func ExpectMapExpvarDeltaWithDeadline(tb testing.TB, name, key string, want int64) func()

ExpectMapExpvarMetricDeltaWithDeadline returns a deferrable function which tests if the expvar map metric with name and key has changed by delta within the given deadline, once the function begins. Before returning, it fetches the original value for comparison.

func ExpectNoDiff

func ExpectNoDiff(tb testing.TB, a, b interface{}, opts ...cmp.Option) bool

ExpectNoDiff tests to see if the two interfaces have no diff. If there is no diff, the retrun value is true. If there is a diff, it is logged to tb and an error is flagged, and the return value is false.

func FatalIfErr

func FatalIfErr(tb testing.TB, err error)

FatalIfErr fails the test with a fatal error if err is not nil.

func FreePort

func FreePort(tb testing.TB) int

func IgnoreFields

func IgnoreFields(typ interface{}, names ...string) cmp.Option

func IgnoreUnexported

func IgnoreUnexported(types ...interface{}) cmp.Option

func LinesReceived

func LinesReceived(lines <-chan *logline.LogLine) (r []*logline.LogLine)

func OpenLogFile

func OpenLogFile(tb testing.TB, name string) *os.File

OpenLogFile creates a new file that emulates being a log.

func SetFlag

func SetFlag(tb testing.TB, name, value string)

SetFlag sets the value of the commandline flag, and registers a cleanup function that restores the flag value.

func SkipIfRoot

func SkipIfRoot(tb testing.TB)

func SkipIfShort

func SkipIfShort(tb testing.TB)

func SortSlices

func SortSlices(lessFunc interface{}) cmp.Option

func TestGetExpvar

func TestGetExpvar(tb testing.TB, name string) expvar.Var

TestGetExpvar fetches the expvar metric `name`, and returns the expvar. Callers are responsible for type assertions on the returned value.

func TestOpenFile

func TestOpenFile(tb testing.TB, name string) *os.File

TestOpenFile creates a new file called name and returns the opened file.

func TestTempDir

func TestTempDir(tb testing.TB) string

TestTempDir creates a temporary directory for use during tests, returning the pathname.

func TimeoutTest

func TimeoutTest(timeout time.Duration, f func(t *testing.T)) func(t *testing.T)

TimeoutTest returns a test function that executes f with a timeout, If the test does not complete in time the test is failed. This lets us set a per-test timeout instead of the global `go test -timeout` coarse timeout.

func WriteString

func WriteString(tb testing.TB, f io.StringWriter, str string) int

Types

This section is empty.

Jump to

Keyboard shortcuts

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