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

Allow mock expectations to be ordered #1106

Merged
merged 3 commits into from Jun 28, 2022

Conversation

brackendawson
Copy link
Contributor

@brackendawson brackendawson commented Jul 26, 2021

Summary

Allow mock expectations to be ordered

Changes

  • Give each Call to be used in Mock.ExpectedCalls a []*Call which must all be satisfied first.
  • Define Call.NotBefore() to allow the above to be populated.
  • Check each call's requirements before processing the found expected call. This needed some existing code to be extracted to a new method Mock.checkExpectation().

Motivation

People want to check that some calls were made in a necessary order.

call1 := mockThing.On("Init").Return(nil)
call2 := mockThing.On("Do").Return(nil).NotBefore(call1)
mockThing.On("Close").Return(nil).NotBefore(call1, call2)

Related issues

Closes #741

boyan-soubachov
boyan-soubachov previously approved these changes Jul 28, 2021
Copy link
Collaborator

@boyan-soubachov boyan-soubachov left a comment

LGTM, thank you for your contribution :)

@boyan-soubachov boyan-soubachov added this to the v1.8.0 milestone Jul 28, 2021
@barp
Copy link

barp commented Nov 2, 2021

When will this be merged?

@ehmm
Copy link

ehmm commented Jun 23, 2022

Are we missing something to merge this?

@boyan-soubachov
Copy link
Collaborator

boyan-soubachov commented Jun 23, 2022

There are conflicts to resolve on mock/mock.go. @brackendawson , do you mind giving them a look? :)

@brackendawson
Copy link
Contributor Author

brackendawson commented Jun 28, 2022

There you go. 🙂

Copy link
Collaborator

@boyan-soubachov boyan-soubachov left a comment

Looks great, thank you!

@boyan-soubachov boyan-soubachov merged commit cf1284f into stretchr:master Jun 28, 2022
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants