Documentation
¶
Index ¶
- Constants
- Variables
- func AssertSendCtx[A any](ctx context.Context, t testing.TB, c chan<- A, a A)
- func Context(t *testing.T, dur time.Duration) context.Context
- func CreateTar(t testing.TB, files map[string]string) []byte
- func CreateTemp(t *testing.T, dir, pattern string) *os.File
- func CreateZip(t testing.TB, files map[string]string) []byte
- func Eventually(ctx context.Context, t testing.TB, ...) (done bool)
- func GenerateTLSCertificate(t testing.TB, commonName string) tls.Certificate
- func GetRandomName(t testing.TB) string
- func Go(t *testing.T, fn func()) (done <-chan struct{})
- func IgnoreLoggedError(entry slog.SinkEntry) bool
- func InCI() bool
- func Logger(t testing.TB) slog.Logger
- func MustRandString(t *testing.T, n int) string
- func PopulateStruct(s interface{}, r *Random) error
- func PromCounterAssertion(t testing.TB, metrics []*dto.MetricFamily, assert func(in float64) bool, ...) bool
- func PromCounterGathered(t testing.TB, metrics []*dto.MetricFamily, name string, labels ...string) bool
- func PromCounterHasValue(t testing.TB, metrics []*dto.MetricFamily, value float64, name string, ...) bool
- func PromGaugeAssertion(t testing.TB, metrics []*dto.MetricFamily, assert func(in float64) bool, ...) bool
- func PromGaugeGathered(t testing.TB, metrics []*dto.MetricFamily, name string, labels ...string) bool
- func PromGaugeHasValue(t testing.TB, metrics []*dto.MetricFamily, value float64, name string, ...) bool
- func RaceEnabled() bool
- func RandomIPv6(t testing.TB) string
- func RandomPort(t *testing.T) int
- func RandomPortNoListen(*testing.T) uint16
- func RequireJSONEq(t *testing.T, expected, actual string)
- func RequireRecvCtx[A any](ctx context.Context, t testing.TB, c <-chan A) (a A)
- func RequireSendCtx[A any](ctx context.Context, t testing.TB, c chan<- A, a A)
- func SkipIfNotTiming(t *testing.T)
- func TempFile(t *testing.T, dir, pattern string) string
- type OAuth2Config
- func (*OAuth2Config) AuthCodeURL(state string, _ ...oauth2.AuthCodeOption) string
- func (*OAuth2Config) Do(_ context.Context, _ promoauth.Oauth2Source, req *http.Request) (*http.Response, error)
- func (c *OAuth2Config) Exchange(_ context.Context, _ string, _ ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (c *OAuth2Config) TokenSource(_ context.Context, _ *oauth2.Token) oauth2.TokenSource
- type OAuth2TokenSource
- type Random
- type TerminalReader
Constants ¶
const ( WaitShort = 10 * time.Second WaitMedium = 15 * time.Second WaitLong = 25 * time.Second WaitSuperLong = 60 * time.Second )
Constants for timing out operations, usable for creating contexts that timeout or in require.Eventually.
const ( IntervalFast = 25 * time.Millisecond IntervalMedium = 250 * time.Millisecond IntervalSlow = time.Second )
Constants for delaying repeated operations, e.g. in require.Eventually.
Variables ¶
var GoleakOptions []goleak.Option = []goleak.Option{ goleak.IgnoreAnyFunction("github.com/cihub/seelog.(*asyncLoopLogger).processQueue"), goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"), goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).mill.func1"), goleak.IgnoreTopFunction("github.com/lib/pq.NewDialListener"), }
GoleakOptions is a common list of options to pass to goleak. This is useful if there is a known leaky function we want to exclude from goleak.
Functions ¶
func AssertSendCtx ¶ added in v2.15.0
func CreateTar ¶ added in v2.18.0
Creates an in-memory tar of the files provided. Files in the archive are written with nobody owner/group, and -rw-rw-rw- permissions.
func CreateTemp ¶
CreateTemp is a convenience function for creating a temporary file, like os.CreateTemp, but it also registers a cleanup function to close and remove the file.
func CreateZip ¶ added in v2.18.0
Creates an in-memory zip of the files provided. Uses archive.CreateZipFromTar under the hood.
func Eventually ¶
func Eventually(ctx context.Context, t testing.TB, condition func(ctx context.Context) (done bool), tick time.Duration, msgAndArgs ...interface{}) (done bool)
Eventually is like require.Eventually except it allows passing a context into the condition. It is safe to use with `require.*`.
If ctx times out, the test will fail, but not immediately. It is the caller's responsibility to exit early if required.
It is the caller's responsibility to ensure that ctx has a deadline or timeout set. Eventually will panic if this is not the case in order to avoid potentially waiting forever.
condition is not run in a goroutine; use the provided context argument for cancellation if required.
func GenerateTLSCertificate ¶
func GenerateTLSCertificate(t testing.TB, commonName string) tls.Certificate
func GetRandomName ¶ added in v2.14.0
GetRandomName returns a random name using moby/pkg/namesgenerator. namesgenerator.GetRandomName exposes a retry parameter that appends a pseudo-random number between 1 and 10 to its return value. While this reduces the probability of collisions, it does not negate them. This function calls namesgenerator.GetRandomName without the retry parameter and instead increments a monotonically increasing integer to the return value.
func Go ¶ added in v2.4.0
Go runs fn in a goroutine and waits until fn has completed before test completion. Done is returned for optionally waiting for fn to exit.
func IgnoreLoggedError ¶ added in v2.18.0
func Logger ¶ added in v2.18.0
Logger returns a "standard" testing logger, with debug level and common flaky errors ignored.
func MustRandString ¶ added in v2.7.0
MustRandString returns a random string of length n.
func PopulateStruct ¶ added in v2.17.0
PopulateStruct does a best effort to populate a struct with random values.
func PromCounterAssertion ¶ added in v2.12.0
func PromCounterGathered ¶ added in v2.12.0
func PromCounterHasValue ¶ added in v2.8.0
func PromGaugeAssertion ¶ added in v2.12.0
func PromGaugeGathered ¶ added in v2.12.0
func PromGaugeHasValue ¶ added in v2.8.0
func RaceEnabled ¶
func RaceEnabled() bool
RaceEnabled returns whether the race detector is enabled. This is a constant at compile time. It should be used to conditionally skip tests that are known to be sensitive to being run with the race detector enabled. Please use sparingly and as a last resort.
func RandomIPv6 ¶ added in v2.21.0
RandomIPv6 returns a random IPv6 address in the 2001:db8::/32 range. 2001:db8::/32 is reserved for documentation and example code.
func RandomPort ¶ added in v2.9.0
RandomPort is a helper function to find a free random port. Note that the OS may reallocate the port very quickly, so this is not _guaranteed_.
func RandomPortNoListen ¶ added in v2.9.0
RandomPortNoListen returns a random port in the ephemeral port range. Does not attempt to listen and close to find a port as the OS may reallocate the port very quickly.
func RequireJSONEq ¶ added in v2.21.0
RequireJSONEq is like assert.RequireJSONEq, but it's actually readable. Note that this calls t.Fatalf under the hood, so it should never be called in a goroutine.
func RequireRecvCtx ¶ added in v2.4.0
func RequireSendCtx ¶ added in v2.7.1
func SkipIfNotTiming ¶
Types ¶
type OAuth2Config ¶
type OAuth2Config struct { Token *oauth2.Token TokenSourceFunc OAuth2TokenSource }
func (*OAuth2Config) AuthCodeURL ¶
func (*OAuth2Config) AuthCodeURL(state string, _ ...oauth2.AuthCodeOption) string
func (*OAuth2Config) Do ¶ added in v2.7.0
func (*OAuth2Config) Do(_ context.Context, _ promoauth.Oauth2Source, req *http.Request) (*http.Response, error)
func (*OAuth2Config) Exchange ¶
func (c *OAuth2Config) Exchange(_ context.Context, _ string, _ ...oauth2.AuthCodeOption) (*oauth2.Token, error)
func (*OAuth2Config) TokenSource ¶
func (c *OAuth2Config) TokenSource(_ context.Context, _ *oauth2.Token) oauth2.TokenSource
type OAuth2TokenSource ¶
type Random ¶ added in v2.17.0
type TerminalReader ¶ added in v2.2.0
type TerminalReader struct {
// contains filtered or unexported fields
}
TerminalReader emulates a terminal and allows matching output. It's important in cases where we can get control sequences to parse them correctly, and keep the state of the terminal across the lifespan of the PTY, since some control sequences are relative to the current cursor position.
func NewTerminalReader ¶ added in v2.2.0
func NewTerminalReader(t *testing.T, r io.Reader) *TerminalReader
func (*TerminalReader) ReadUntil ¶ added in v2.2.0
func (tr *TerminalReader) ReadUntil(ctx context.Context, matcher func(line string) bool) (retErr error)
ReadUntil emulates a terminal and reads one byte at a time until the matcher returns true or the context expires. If the matcher is nil, read until EOF. The PTY must be sized to 80x80 or there could be unexpected results.
func (*TerminalReader) ReadUntilString ¶ added in v2.2.0
func (tr *TerminalReader) ReadUntilString(ctx context.Context, want string) error
ReadUntilString emulates a terminal and reads one byte at a time until we either see the string we want, or the context expires. The PTY must be sized to 80x80 or there could be unexpected results.