package testutil
import "go.etcd.io/etcd/client/pkg/v3/testutil"
Package testutil provides test utility functions.
Index ¶
- Variables
- func AssertEqual(t *testing.T, e, a interface{}, msg ...string)
- func AssertFalse(t *testing.T, v bool, msg ...string)
- func AssertNil(t *testing.T, v interface{})
- func AssertNotNil(t *testing.T, v interface{})
- func AssertTrue(t *testing.T, v bool, msg ...string)
- func CheckAfterTest(d time.Duration) error
- func CheckLeakedGoroutine() bool
- func ExitInShortMode(reason string)
- func FatalStack(t *testing.T, s string)
- func MustCheckLeakedGoroutine()
- func MustNewURL(t *testing.T, s string) *url.URL
- func MustNewURLs(t *testing.T, urls []string) []url.URL
- func MustTestMainWithLeakDetection(m *testing.M)
- func Poll(interval time.Duration, timeout time.Duration, condition ConditionFunc) (bool, error)
- func RegisterLeakDetection(t TB)
- func SkipTestIfShortMode(t TB, reason string)
- func WaitSchedule()
- type Action
- type ConditionFunc
- type PauseableHandler
- func (ph *PauseableHandler) Pause()
- func (ph *PauseableHandler) Resume()
- func (ph *PauseableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Recorder
- func NewRecorderStream() Recorder
- func NewRecorderStreamWithWaitTimout(waitTimeout time.Duration) Recorder
- type RecorderBuffered
- func (r *RecorderBuffered) Action() []Action
- func (r *RecorderBuffered) Chan() <-chan Action
- func (r *RecorderBuffered) Record(a Action)
- func (r *RecorderBuffered) Wait(n int) (acts []Action, err error)
- type TB
Variables ¶
Functions ¶
func AssertEqual ¶
func AssertFalse ¶
func AssertNil ¶
func AssertNotNil ¶
func AssertTrue ¶
func CheckAfterTest ¶
CheckAfterTest returns an error if AfterTest would fail with an error. Waits for go-routines shutdown for 'd'.
func CheckLeakedGoroutine ¶
func CheckLeakedGoroutine() bool
CheckLeakedGoroutine verifies tests do not leave any leaky goroutines. It returns true when there are goroutines still running(leaking) after all tests.
import "go.etcd.io/etcd/client/pkg/v3/testutil" func TestMain(m *testing.M) { testutil.MustTestMainWithLeakDetection(m) } func TestSample(t *testing.T) { RegisterLeakDetection(t) ... }
func ExitInShortMode ¶
func ExitInShortMode(reason string)
ExitInShortMode closes the current process (with 0) if the short test mode detected.
To be used in Test-main, where test context (testing.TB) is not available.
Requires custom env-variable (GOLANG_TEST_SHORT) apart of `go test --short flag`.
func FatalStack ¶
FatalStack helps to fatal the test and print out the stacks of all running goroutines.
func MustCheckLeakedGoroutine ¶
func MustCheckLeakedGoroutine()
func MustNewURL ¶
func MustNewURLs ¶
func MustTestMainWithLeakDetection ¶
MustTestMainWithLeakDetection expands standard m.Run with leaked goroutines detection.
func Poll ¶
Poll calls a condition function repeatedly on a polling interval until it returns true, returns an error or the timeout is reached. If the condition function returns true or an error before the timeout, Poll immediately returns with the true value or the error. If the timeout is exceeded, Poll returns false.
func RegisterLeakDetection ¶
func RegisterLeakDetection(t TB)
RegisterLeakDetection is a convenient way to register before-and-after code to a test. If you execute RegisterLeakDetection, you don't need to explicitly register AfterTest.
func SkipTestIfShortMode ¶
func WaitSchedule ¶
func WaitSchedule()
WaitSchedule briefly sleeps in order to invoke the go scheduler. TODO: improve this when we are able to know the schedule or status of target go-routine.
Types ¶
type Action ¶
type Action struct { Name string Params []interface{} }
type ConditionFunc ¶
ConditionFunc returns true when a condition is met.
type PauseableHandler ¶
func (*PauseableHandler) Pause ¶
func (ph *PauseableHandler) Pause()
func (*PauseableHandler) Resume ¶
func (ph *PauseableHandler) Resume()
func (*PauseableHandler) ServeHTTP ¶
func (ph *PauseableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Recorder ¶
type Recorder interface { // Record publishes an Action (e.g., function call) which will // be reflected by Wait() or Chan() Record(a Action) // Wait waits until at least n Actions are available or returns with error Wait(n int) ([]Action, error) // Action returns immediately available Actions Action() []Action // Chan returns the channel for actions published by Record Chan() <-chan Action }
func NewRecorderStream ¶
func NewRecorderStream() Recorder
func NewRecorderStreamWithWaitTimout ¶
type RecorderBuffered ¶
RecorderBuffered appends all Actions to a slice
func (*RecorderBuffered) Action ¶
func (r *RecorderBuffered) Action() []Action
func (*RecorderBuffered) Chan ¶
func (r *RecorderBuffered) Chan() <-chan Action
func (*RecorderBuffered) Record ¶
func (r *RecorderBuffered) Record(a Action)
func (*RecorderBuffered) Wait ¶
func (r *RecorderBuffered) Wait(n int) (acts []Action, err error)
type TB ¶
type TB interface { Cleanup(func()) Error(args ...interface{}) Errorf(format string, args ...interface{}) Fail() FailNow() Failed() bool Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Logf(format string, args ...interface{}) Name() string TempDir() string Helper() Skip(args ...interface{}) }
TB is a subset of methods of testing.TB interface. We cannot implement testing.TB due to protection, so we expose this simplified interface.
func NewTestingTBProthesis ¶
NewTestingTBProthesis creates a fake variant of testing.TB implementation. It's supposed to be used in contexts were real testing.T is not provided, e.g. in 'examples'.
The `closef` goroutine should get executed when tb will not be needed any longer.
The provided implementation is NOT thread safe (Cleanup() method).
Source Files ¶
assert.go leak.go pauseable_handler.go recorder.go testingtb.go testutil.go var.go
- Version
- v3.5.18 (latest)
- Published
- Jan 24, 2025
- Platform
- linux/amd64
- Imports
- 15 packages
- Last checked
- 5 days ago –
Tools for package owners.