expect

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attach

Attach an expectation to a receiver. If the expectation is not satisfied, the receiver will not Pass.

func Fail

Types

type ExpectOpt

type ExpectOpt func(o expectOpts) expectOpts

func Absolute

func Absolute(nthMsg int) ExpectOpt

specify that an expectation should match the Nth msg received by the TestReceiver

func AnyTimes

func AnyTimes() ExpectOpt

Expectation is satisifed if it is executed zero or more times. Ensure that you are sleeping the test or have other expectations so [TestReciever.Wait] does not exit immediately

func AtLeast

func AtLeast(n int) ExpectOpt

expectation will pass only if matched >=[n] times.

func AtMost

func AtMost(n int) ExpectOpt

Expectation is satisifed if it is executed up to [n] times. Zero executions will also pass WARNING: this expectation will cause your test to run until [WaitTimeout] is exceeded

func Name

func Name(name string) ExpectOpt

Set a name that will identify the Expectation in error reports and logs

func Never

func Never() ExpectOpt

expectation will pass only if never matched. Alias for `Times(0)` WARNING: this expectation will cause your test to run until [WaitTimeout] is exceeded

func Receiver

func Receiver(tr *erltest.TestReceiver) ExpectOpt

Set the TestReceiver that the expectation will add itself to. Useful when you are registering [Simple] sub-expectations

func Times

func Times(n int) ExpectOpt

Expectation is satisifed only if it is invoed [n] times.

type Expectation

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

func AttachDeepEqual

func AttachDeepEqual(tr *erltest.TestReceiver, expected any, cmpOpts []cmp.Option, opts ...ExpectOpt) *Expectation

func AttachEquals

func AttachEquals(tr *erltest.TestReceiver, expected any, opts ...ExpectOpt) *Expectation

Create an Equals expectation and attach it to [tr]

func Called

func Called(opts ...ExpectOpt) *Expectation

Set an expectation that will pass if it is matched (or not matched, depending on opts). Useful if we don't care about a message's contents

func DeepEqual

func DeepEqual(t *testing.T, expected any, cmpOpts []cmp.Option, opts ...ExpectOpt) *Expectation

func Equals

func Equals(t *testing.T, expected any, opts ...ExpectOpt) *Expectation

assert a message equals exactly

func Expect

func Expect(f func(arg erltest.ExpectArg) bool, opts ...ExpectOpt) *Expectation

a simple terminal expectation that works well with check.Chain

func New

func New(te Handle, opts ...ExpectOpt) *Expectation

Create a custom expectation that can branch to other expectations

IMPORTANT: Any expectation used in a handler needs to be [Attach]ed to a test receiver. If there are multiple possible expectations that can be returned here, they all need to be attached to make sure the [TestReceiver] does not pass without checking them.

func (*Expectation) And

func (ex *Expectation) And(exs ...*Expectation)

Joins [ex] with the [exs], so that all [exs] must succeed in order for [ex.Satisfied] to pass. WARNING: any *Expectation returned from an[exs] is ignored. This prevents branching, which can be accomplished by composing exceptions inside a Handle.

func (*Expectation) Check

func (ex *Expectation) Check(arg erltest.ExpectArg) (next erltest.Expectation, failure *erltest.ExpectationFailure)

[Check] should be executed after a "match" has been made to the expectation. It will return an error if it has been clearly executed too many times. If you want to evaluate if an Expectation has "passed", you should call [Satisified].

func (*Expectation) ID

func (ex *Expectation) ID() string

func (*Expectation) Name

func (ex *Expectation) Name() string

func (*Expectation) Satisfied

func (ex *Expectation) Satisfied(testEnded bool) bool

Returns true if this and all joined exceptions are satisifed, and immediately if it encounters a failure.

If [testEnded] is true, checks that should never be executed (ie: Times(0)) will be evaluated.

func (*Expectation) String

func (ex *Expectation) String() string

Jump to

Keyboard shortcuts

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