testerr

package
v1.0.0-dev.10 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Err = errors.New("test error")

Functions

func MaybeFail

func MaybeFail[T any](ct *Calltracker, f func() (T, error)) (T, error)

MaybeFail fails the call if the next value in Fails is true.

func MaybeFailErrFunc

func MaybeFailErrFunc(ct *Calltracker, f func() error) error

MaybeFailErrFunc fails the call if the next value in Fails is true.

Types

type Calltracker

type Calltracker struct {
	CallIndex         int
	ShouldFail        bool
	Err               error
	FailAllAfterIndex bool
	FailAtIndex       int
}

Calltracker is a helper struct to track calls to a dependency. It can be used to simulate failing dependencies. The zero value is ready to use and will never fail.

func NewFailingDeps

func NewFailingDeps(err error, expectCalls int) []Calltracker

NewFailingDeps will create failing calltrackers that will fail at different points in the call sequence.

Dependencies will fail in two ways: - A single failure, then all calls after succesful. - All calls will fail after a number of succesful calls.

Jump to

Keyboard shortcuts

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