Documentation
¶
Overview ¶
Package test contains internal testing utilities.
Index ¶
- func Expect[T any](t FailerT, failMessage string, got, want T, options ...cmp.Option)
- func ExpectChannelToBlockForDuration[T any](t TestingT, d time.Duration, ch <-chan T, options ...cmp.Option)
- func ExpectChannelToClose[T any](t TestingT, ch <-chan T, options ...cmp.Option)
- func ExpectChannelToReceive[T any](t FailerT, ch <-chan T, want T, options ...cmp.Option) (got T)
- func ExpectChannelWouldBlock[T any](t TestingT, ch <-chan T, options ...cmp.Option)
- func FailAfterJournalAppend[T proto.Message](s *memoryjournal.BinaryStore, name string, pred func(T) bool, err error)
- func FailAfterKeyspaceSet(s *memorykv.BinaryStore, name string, pred func(k, v []byte) bool)
- func FailBeforeJournalAppend[T proto.Message](s *memoryjournal.BinaryStore, name string, pred func(T) bool, err error)
- func FailBeforeKeyspaceSet(s *memorykv.BinaryStore, name string, pred func(k, v []byte) bool)
- func FailOnJournalOpen(s *memoryjournal.BinaryStore, name string, err error)
- func FailOnce(err error) func() error
- type Context
- type FailerT
- type Task
- type TaskRunner
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpectChannelToBlockForDuration ¶
func ExpectChannelToBlockForDuration[T any]( t TestingT, d time.Duration, ch <-chan T, options ...cmp.Option, )
ExpectChannelToBlockForDuration expects reading from the channel to block until the given duration elapses.
func ExpectChannelToClose ¶
ExpectChannelToClose waits until a channel is closed.
func ExpectChannelToReceive ¶
func ExpectChannelToReceive[T any]( t FailerT, ch <-chan T, want T, options ...cmp.Option, ) (got T)
ExpectChannelToReceive waits until a value is received from a channel and then compares it to the expected value.
func ExpectChannelWouldBlock ¶
ExpectChannelWouldBlock expects reading from the channel would block.
func FailAfterJournalAppend ¶
func FailAfterJournalAppend[T proto.Message]( s *memoryjournal.BinaryStore, name string, pred func(T) bool, err error, )
FailAfterJournalAppend configures the journal with the given name to return an error on the next call to Append() with a record that satisifies the given predicate function.
The error is returned after the append is actually performed.
func FailAfterKeyspaceSet ¶
func FailAfterKeyspaceSet( s *memorykv.BinaryStore, name string, pred func(k, v []byte) bool, )
FailAfterKeyspaceSet configures the keyspace with the given name to return an error on the next call to Set() with a key/value pair that satisifies the given predicate function.
The error is returned after the set is actually performed.
func FailBeforeJournalAppend ¶
func FailBeforeJournalAppend[T proto.Message]( s *memoryjournal.BinaryStore, name string, pred func(T) bool, err error, )
FailBeforeJournalAppend configures the journal with the given name to return an error on the next call to Append() with a record that satisifies the given predicate function.
The error is returned before the append is actually performed.
func FailBeforeKeyspaceSet ¶
func FailBeforeKeyspaceSet( s *memorykv.BinaryStore, name string, pred func(k, v []byte) bool, )
FailBeforeKeyspaceSet configures the keyspace with the given name to return an error on the next call to Set() with a key/value pair that satisifies the given predicate function.
The error is returned before the set is actually performed.
func FailOnJournalOpen ¶
func FailOnJournalOpen( s *memoryjournal.BinaryStore, name string, err error, )
FailOnJournalOpen configures the journal with the given name to return an error on the next call to Open().
Types ¶
type Context ¶
Context is a context that is also a TestingT.
func WithContext ¶
WithContext returns a context that is bound to the lifetime of the test.
type FailerT ¶
type FailerT interface { Helper() Log(...any) Logf(string, ...any) Fatal(...any) Fatalf(string, ...any) Error(...any) Errorf(string, ...any) }
FailerT is the subset of the testing.TB interface that is used by parts of this package that only need to cause tests to fail.
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task represents a function running in the background.
func (*Task) Done ¶
func (t *Task) Done() <-chan struct{}
Done returns a channel that is closed when the function returns.
func (*Task) Err ¶
Err returns the error returned by the function.
It panics if the function has not yet returned.
func (*Task) StopAndWait ¶
func (t *Task) StopAndWait()
StopAndWait cancels the context passed to the function and waits for it to return.
If it returns an error, the test fails.
func (*Task) WaitForSuccess ¶
func (t *Task) WaitForSuccess()
WaitForSuccess waits for the function to return successfully.
If it returns an error, the test fails.
func (*Task) WaitUntilStopped ¶
func (t *Task) WaitUntilStopped()
WaitUntilStopped waits for the function to be explicitly stopped
If it returns an error, the test fails.
type TaskRunner ¶
type TaskRunner struct {
// contains filtered or unexported fields
}
TaskRunner launches a task in the background.
func RunInBackground ¶
RunInBackground returns a TaskRunner that executes fn in its own goroutine.
func (TaskRunner) BeforeTestEnds ¶
func (r TaskRunner) BeforeTestEnds() *Task
BeforeTestEnds executes the task in its own goroutine with the expectation that it will return successfully before the test ends.
func (TaskRunner) FailBeforeTestEnds ¶
func (r TaskRunner) FailBeforeTestEnds() *Task
FailBeforeTestEnds executes the task in its own goroutine with the expectation that it will return an error before the test ends.
func (TaskRunner) RepeatedlyUntilStopped ¶
func (r TaskRunner) RepeatedlyUntilStopped() *Task
RepeatedlyUntilStopped executes the task in its own goroutine, restarting it if it returns before it is stopped explicitly or the test ends.
func (TaskRunner) RepeatedlyUntilSuccess ¶
func (r TaskRunner) RepeatedlyUntilSuccess() *Task
RepeatedlyUntilSuccess executes the task in its own goroutine, restarting it if it returns an error before the test ends.
func (TaskRunner) UntilStopped ¶
func (r TaskRunner) UntilStopped() *Task
UntilStopped executes the task in its own goroutine with the expectation that it will not return until it is stopped explicitly, or the test ends.
func (TaskRunner) UntilTestEnds ¶
func (r TaskRunner) UntilTestEnds() *Task
UntilTestEnds executes the task in its own goroutine with the expectation that it will not return before the test ends.
type TestingT ¶
type TestingT interface { FailerT Helper() Cleanup(func()) }
TestingT is the subset of the testing.TB interface that is used by this package.