testutil

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
const (
	IntervalFast   = 25 * time.Millisecond
	IntervalMedium = 250 * time.Millisecond
	IntervalSlow   = time.Second
)

Constants for delaying repeated operations, e.g. in require.Eventually.

Variables

This section is empty.

Functions

func Context

func Context(t *testing.T, dur time.Duration) context.Context

func CreateTemp

func CreateTemp(t *testing.T, dir, pattern string) *os.File

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 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 InCI

func InCI() bool

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 ReadUntil

func ReadUntil(ctx context.Context, t *testing.T, r io.Reader, matcher func(line string) bool) 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 ReadUntilString

func ReadUntilString(ctx context.Context, t *testing.T, want string, r io.Reader) 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.

func SkipIfNotTiming

func SkipIfNotTiming(t *testing.T)

func TempFile

func TempFile(t *testing.T, dir, pattern string) string

TempFile returns the name of a temporary file that does not exist.

Types

type OAuth2Config

type OAuth2Config struct {
	Token           *oauth2.Token
	TokenSourceFunc OAuth2TokenSource
}

func (*OAuth2Config) AuthCodeURL

func (*OAuth2Config) AuthCodeURL(state string, _ ...oauth2.AuthCodeOption) string

func (*OAuth2Config) Exchange

func (*OAuth2Config) TokenSource

func (c *OAuth2Config) TokenSource(_ context.Context, _ *oauth2.Token) oauth2.TokenSource

type OAuth2TokenSource

type OAuth2TokenSource func() (*oauth2.Token, error)

func (OAuth2TokenSource) Token

func (o OAuth2TokenSource) Token() (*oauth2.Token, error)

Jump to

Keyboard shortcuts

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