testutil

package
v0.310.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 222

Documentation

Index

Constants

View Source
const (

	// NilCloser is a no-op Closer.
	NilCloser = nilCloser(true)
)

Variables

This section is empty.

Functions

func DirHash

func DirHash(t *testing.T, path string) []byte

DirHash returns a hash of all files attributes and their content within a directory.

func NewRoundTripCheckRequest

func NewRoundTripCheckRequest(checkRequest func(*http.Request), theResponse *http.Response, theError error) http.RoundTripper

NewRoundTripCheckRequest creates a new instance of a type that implements http.RoundTripper, which before returning theResponse and theError, executes checkRequest against a http.Request.

func RandomUnprivilegedPort

func RandomUnprivilegedPort(t *testing.T) int

RandomUnprivilegedPort returns valid unprivileged random port number which can be used for testing.

func RequireEqual added in v0.51.0

func RequireEqual(t testing.TB, expected, actual any, msgAndArgs ...any)

RequireEqual is a replacement for require.Equal using go-cmp adapted for Prometheus data structures, instead of DeepEqual.

func RequireEqualWithOptions added in v0.51.0

func RequireEqualWithOptions(t testing.TB, expected, actual any, extra []cmp.Option, msgAndArgs ...any)

RequireEqualWithOptions works like RequireEqual but allows extra cmp.Options.

func TolerantVerifyLeak

func TolerantVerifyLeak(m *testing.M)

TolerantVerifyLeak verifies go leaks but excludes the go routines that are launched as side effects of some of our dependencies.

Types

type Closer

type Closer interface {
	// Close reaps the underlying directory and its children. The directory
	// could be deleted by its users already.
	Close()
}

Closer is the interface that wraps the Close method.

func NewCallbackCloser

func NewCallbackCloser(fn func()) Closer

NewCallbackCloser returns a Closer that calls the provided function upon closing.

type MockContext

type MockContext struct {
	Error  error
	DoneCh chan struct{}
}

A MockContext provides a simple stub implementation of a Context.

func (*MockContext) Deadline

func (*MockContext) Deadline() (deadline time.Time, ok bool)

Deadline always will return not set.

func (*MockContext) Done

func (c *MockContext) Done() <-chan struct{}

Done returns a read channel for listening to the Done event.

func (*MockContext) Err

func (c *MockContext) Err() error

Err returns the error, is nil if not set.

func (*MockContext) Value

func (*MockContext) Value(any) any

Value ignores the Value and always returns nil.

type MockContextErrAfter added in v0.53.0

type MockContextErrAfter struct {
	MockContext
	FailAfter uint64
	// contains filtered or unexported fields
}

MockContextErrAfter is a MockContext that will return an error after a certain number of calls to Err().

func (*MockContextErrAfter) Count added in v0.53.0

func (c *MockContextErrAfter) Count() uint64

func (*MockContextErrAfter) Err added in v0.53.0

func (c *MockContextErrAfter) Err() error

type TemporaryDirectory

type TemporaryDirectory interface {
	Closer

	// Path returns the underlying path for access.
	Path() string
}

TemporaryDirectory models a closeable path for transient POSIX disk activities.

func NewTemporaryDirectory

func NewTemporaryDirectory(name string, t testing.TB) (handler TemporaryDirectory)

NewTemporaryDirectory creates a new temporary directory for transient POSIX activities.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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