test

package
v1.0.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eventually

func Eventually(t Failer, name string, cond Condition)

Eventually polls cond until it completes (returns true) or times out (resulting in a test failure).

func JSONEquals

func JSONEquals(t Failer, a, b string)

JSONEquals compares two json strings. We cannot compare JSON strings from protobuf because of design decisions https://github.com/golang/protobuf/issues/1373 Instead, use this function to normalize the formatting

func SetBoolForTest

func SetBoolForTest(t Failer, vv *bool, v bool)

SetBoolForTest sets a variable for the duration of a test, then resets it once the test is complete.

func SetDurationForTest

func SetDurationForTest(t Failer, vv *time.Duration, v time.Duration)

SetDurationForTest sets a variable for the duration of a test, then resets it once the test is complete.

func SetEnvForTest

func SetEnvForTest(t Failer, k, v string)

SetEnvForTest sets an environment variable for the duration of a test, then resets it once the test is complete.

func SetFloatForTest

func SetFloatForTest(t Failer, vv *float64, v float64)

SetFloatForTest sets a variable for the duration of a test, then resets it once the test is complete.

func SetStringForTest

func SetStringForTest(t Failer, vv *string, v string)

SetStringForTest sets a variable for the duration of a test, then resets it once the test is complete.

func Wrap

func Wrap(f func(t Failer)) error

Wrap executes a function with a fake Failer, and returns an error if the test failed. This allows calling functions that take a Failer and using them with functions that expect an error, or allowing calling functions that would cause a test to immediately fail to instead return an error. Wrap handles Cleanup() and short-circuiting of Fatal() just like the real testing.T.

Types

type Condition

type Condition func() bool

A Condition is a function that returns true when a test condition is satisfied.

type EventualOpts

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

EventualOpts defines a polling strategy for operations that must eventually succeed. A new EventualOpts must be provided for each invocation of Eventually (or call Reset on a previously completed set of options).

func NewEventualOpts

func NewEventualOpts(interval, deadline time.Duration) *EventualOpts

NewEventualOpts constructs an EventualOpts instance with the provided polling interval and deadline. EventualOpts will perform randomized exponential backoff using the starting interval, and will stop polling (and therefore fail) after deadline time as elapsed from calling Eventually.

Note: we always backoff with a randomization of 0.5 (50%), a multiplier of 1.5, and a max interval of one minute.

func (EventualOpts) Eventually

func (e EventualOpts) Eventually(t Failer, name string, cond Condition)

Eventually polls cond until it succeeds (returns true) or we exceed the deadline. Eventually performs backoff while polling cond.

name is printed as part of the test failure message when we exceed the deadline to help identify the test case failing. cond does not need to be thread-safe: it is only called from the current goroutine. cond itself can also fail the test early using t.Fatal.

type Failer

type Failer interface {
	Fail()
	FailNow()
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Log(args ...interface{})
	Logf(format string, args ...interface{})
	TempDir() string
	Helper()
	Cleanup(func())
}

Failer is an interface to be provided to test functions of the form XXXOrFail. This is a substitute for testing.TB, which cannot be implemented outside of the testing package.

Directories

Path Synopsis
ca
csrctrl
controllers
An example implementation of a CSR Controller.
An example implementation of a CSR Controller.
signer
Package signer implements a CA signer that uses keys stored on local disk.
Package signer implements a CA signer that uses keys stored on local disk.
datasets
fakes
components/containerregistry
Package containerregistry provides basic utilities around configuring the fake container registry server component for integration testing.
Package containerregistry provides basic utilities around configuring the fake container registry server component for integration testing.
components/gcemetadata
Package gcemetadata provides basic utilities around configuring the fake GCE Metadata Server component for integration testing.
Package gcemetadata provides basic utilities around configuring the fake GCE Metadata Server component for integration testing.
loadbalancersim
util
yml

Jump to

Keyboard shortcuts

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