Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[*] add documentation for CallModifier interface #183

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ type expectation interface {
fmt.Stringer
}

type CallModifyer interface {
Maybe() CallModifyer
Times(n uint) CallModifyer
WillDelayFor(duration time.Duration) CallModifyer
// CallModifier interface represents common interface for all expectations supported
type CallModifier interface {
// Maybe allows the expected method call to be optional.
// Not calling an optional method will not cause an error while asserting expectations
Maybe() CallModifier
// Times indicates that that the expected method should only fire the indicated number of times.
// Zero value is ignored and means the same as one.
Times(n uint) CallModifier
// WillDelayFor allows to specify duration for which it will delay
// result. May be used together with Context
WillDelayFor(duration time.Duration) CallModifier
// WillReturnError allows to set an error for the expected method
WillReturnError(err error)
// WillPanic allows to force the expected method to panic
WillPanic(v any)
}

Expand Down Expand Up @@ -72,35 +81,27 @@ func (e *commonExpectation) waitForDelay(ctx context.Context) (err error) {
return err
}

// Maybe allows the expected method call to be optional.
// Not calling an optional method will not cause an error while asserting expectations
func (e *commonExpectation) Maybe() CallModifyer {
func (e *commonExpectation) Maybe() CallModifier {
e.optional = true
return e
}

// Times indicates that that the expected method should only fire the indicated number of times.
// Zero value is ignored and means the same as one.
func (e *commonExpectation) Times(n uint) CallModifyer {
func (e *commonExpectation) Times(n uint) CallModifier {
e.plannedCalls = n
return e
}

// WillDelayFor allows to specify duration for which it will delay
// result. May be used together with Context
func (e *commonExpectation) WillDelayFor(duration time.Duration) CallModifyer {
func (e *commonExpectation) WillDelayFor(duration time.Duration) CallModifier {
e.plannedDelay = duration
return e
}

// WillReturnError allows to set an error for the expected method
func (e *commonExpectation) WillReturnError(err error) {
e.err = err
}

var errPanic = errors.New("pgxmock panic")

// WillPanic allows to force the expected method to panic
func (e *commonExpectation) WillPanic(v any) {
e.err = errPanic
e.panicArgument = v
Expand Down
Loading