testutil

package
v0.0.0-...-d45231a Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConnecting = errors.New("connection error")
View Source
var ErrInvalidArgument = errors.New("invalid argument")
View Source
var ErrInvalidState = errors.New("invalid state")
View Source
var ErrTimeout = errors.New("timeout error")
View Source
var GetFalseFn = func() (bool, error) {
	return false, nil
}
View Source
var GetTrueFn = func() (bool, error) {
	return true, nil
}
View Source
var NoopFn = func() error {
	return nil
}

Functions

func AssertDuration

func AssertDuration(t *testing.T, expectedDuration int, actualDuration time.Duration)

func ErrorNTimesThenError

func ErrorNTimesThenError[R any](err error, errorTimes int, finalError error) func(exec failsafe.Execution[R]) (R, error)

ErrorNTimesThenError returns a stub function that returns the err errorTimes and then returns the finalError. Can be used with failsafe.GetWithExecution.

func ErrorNTimesThenPanic

func ErrorNTimesThenPanic[R any](err error, errorTimes int, panicValue any) func(exec failsafe.Execution[R]) (R, error)

ErrorNTimesThenPanic returns a stub function that returns the err errorTimes and then panics with the panicValue. Can be used with failsafe.GetWithExecution.

func ErrorNTimesThenReturn

func ErrorNTimesThenReturn[R any](err error, errorTimes int, results ...R) (fn func(exec failsafe.Execution[R]) (R, error), resetFn func())

ErrorNTimesThenReturn returns a stub function that returns the err errorTimes and then returns the results. Can be used with failsafe.GetWithExecution.

func GetFn

func GetFn[R any](result R, err error) func() (R, error)

func GetType

func GetType(myvar interface{}) string

func GetWithExecutionFn

func GetWithExecutionFn[R any](result R, err error) func(exec failsafe.Execution[R]) (R, error)

func MillisToNanos

func MillisToNanos(millis int) int64

func RunFn

func RunFn(err error) func() error

func SetupWithContextSleep

func SetupWithContextSleep(sleepTime time.Duration) func() context.Context

SetupWithContextSleep returns a setup function that provides a context that is canceled after the sleepTime.

func TestGetFailure

func TestGetFailure[R any](t *testing.T, given Given, executor failsafe.Executor[R], when WhenGet[R], expectedAttempts int, expectedExecutions int, expectedError error)

func TestGetSuccess

func TestGetSuccess[R any](t *testing.T, given Given, executor failsafe.Executor[R], when WhenGet[R], expectedAttempts int, expectedExecutions int, expectedResult R)

func TestRunFailure

func TestRunFailure[R any](t *testing.T, given Given, executor failsafe.Executor[R], when WhenRun[R], expectedAttempts int, expectedExecutions int, expectedError error)

func TestRunSuccess

func TestRunSuccess[R any](t *testing.T, given Given, executor failsafe.Executor[R], when WhenRun[R], expectedAttempts int, expectedExecutions int)

func Timed

func Timed(fn func()) time.Duration

func WaitAndAssertCanceled

func WaitAndAssertCanceled[R any](t *testing.T, waitDuration time.Duration, exec failsafe.Execution[R])

Types

type CompositeError

type CompositeError struct {
	Cause error
}

func (*CompositeError) Error

func (ce *CompositeError) Error() string

func (*CompositeError) Is

func (ce *CompositeError) Is(err error) bool

func (*CompositeError) Unwrap

func (ce *CompositeError) Unwrap() error

type Given

type Given func() context.Context

type TestClock

type TestClock struct {
	CurrentTime int64
}

func (*TestClock) CurrentUnixNano

func (t *TestClock) CurrentUnixNano() int64

type TestExecution

type TestExecution[R any] struct {
	TheLastResult R
}

func (TestExecution[R]) AttemptStartTime

func (s TestExecution[R]) AttemptStartTime() time.Time

func (TestExecution[R]) Attempts

func (s TestExecution[R]) Attempts() int

func (TestExecution[R]) Canceled

func (s TestExecution[R]) Canceled() <-chan any

func (TestExecution[R]) Context

func (s TestExecution[R]) Context() context.Context

func (TestExecution[R]) ElapsedAttemptTime

func (s TestExecution[R]) ElapsedAttemptTime() time.Duration

func (TestExecution[R]) ElapsedTime

func (s TestExecution[R]) ElapsedTime() time.Duration

func (TestExecution[R]) Executions

func (s TestExecution[R]) Executions() int

func (TestExecution[R]) IsCanceled

func (s TestExecution[R]) IsCanceled() bool

func (TestExecution[R]) IsFirstAttempt

func (s TestExecution[R]) IsFirstAttempt() bool

func (TestExecution[R]) IsRetry

func (s TestExecution[R]) IsRetry() bool

func (TestExecution[R]) LastError

func (s TestExecution[R]) LastError() error

func (TestExecution[R]) LastResult

func (s TestExecution[R]) LastResult() R

func (TestExecution[R]) StartTime

func (s TestExecution[R]) StartTime() time.Time

type TestStopwatch

type TestStopwatch struct {
	CurrentTime int64
}

func (*TestStopwatch) ElapsedTime

func (t *TestStopwatch) ElapsedTime() time.Duration

func (*TestStopwatch) Reset

func (t *TestStopwatch) Reset()

type Waiter

type Waiter struct {
	// contains filtered or unexported fields
}

func NewWaiter

func NewWaiter() *Waiter

func (*Waiter) AssertEqual

func (w *Waiter) AssertEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) bool

func (*Waiter) Await

func (w *Waiter) Await(expectedResumes int)

func (*Waiter) AwaitWithTimeout

func (w *Waiter) AwaitWithTimeout(expectedResumes int, timeout time.Duration)

func (*Waiter) Resume

func (w *Waiter) Resume()

type WhenGet

type WhenGet[R any] func(execution failsafe.Execution[R]) (R, error)

type WhenRun

type WhenRun[R any] func(execution failsafe.Execution[R]) error

Jump to

Keyboard shortcuts

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