-
Notifications
You must be signed in to change notification settings - Fork 1.7k
mock: in order mock calls #1637
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a unit test, please.
unit test added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Positive and negative tests, nice one. 👍 Just a couple of small comments.
mock/mock_test.go
Outdated
c, | ||
) | ||
|
||
require.Equal(t, []*Call{b, c}, mockedService.ExpectedCalls) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is testing the implementation. A cost effective test would only test the behaviour, as you are doing just fine after this line.
If you remove this assertion then we are free to change the implementation of the intended behaviour without breaking the test. It also removes the need to declare b
and c
, so the test can be written as InOrder
is intended to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it's just comparing pointer values. If InOrder did literally nothing then that assertion would still pass.
(requested changes applied)
Good comments, thanks! Requested changes applied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, should be helpful to all the developers moving from gomock. I'll give some time for other maintainers to review before I merge.
Ah you beat me to it, thanks! And missed that existing PR |
Hello, any ETA on merging this PR? |
Thanks @ReyOrtiz. This can be consumed now by gomock expats with: |
Thanks @brackendawson for all the help! 🙏 |
…nercloud/fleeting-plugin-hetzner!175) This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/stretchr/testify](https://github.com/stretchr/testify) | require | minor | `v1.9.0` -> `v1.10.0` | --- ### Release Notes <details> <summary>stretchr/testify (github.com/stretchr/testify)</summary> ### [`v1.10.0`](https://github.com/stretchr/testify/releases/tag/v1.10.0) [Compare Source](stretchr/testify@v1.9.0...v1.10.0) #### What's Changed ##### Functional Changes - Add PanicAssertionFunc by [@​fahimbagar](https://github.com/fahimbagar) in stretchr/testify#1337 - assert: deprecate CompareType by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1566 - assert: make YAML dependency pluggable via build tags by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1579 - assert: new assertion NotElementsMatch by [@​hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1600 - mock: in order mock calls by [@​ReyOrtiz](https://github.com/ReyOrtiz) in stretchr/testify#1637 - Add assertion for NotErrorAs by [@​palsivertsen](https://github.com/palsivertsen) in stretchr/testify#1129 - Record Return Arguments of a Call by [@​jayd3e](https://github.com/jayd3e) in stretchr/testify#1636 - assert.EqualExportedValues: accepts everything by [@​redachl](https://github.com/redachl) in stretchr/testify#1586 ##### Fixes - assert: make tHelper a type alias by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1562 - Do not get argument again unnecessarily in Arguments.Error() by [@​TomWright](https://github.com/TomWright) in stretchr/testify#820 - Fix time.Time compare by [@​myxo](https://github.com/myxo) in stretchr/testify#1582 - assert.Regexp: handle \[]byte array properly by [@​kevinburkesegment](https://github.com/kevinburkesegment) in stretchr/testify#1587 - assert: collect.FailNow() should not panic by [@​marshall-lee](https://github.com/marshall-lee) in stretchr/testify#1481 - mock: simplify implementation of FunctionalOptions by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1571 - mock: caller information for unexpected method call by [@​spirin](https://github.com/spirin) in stretchr/testify#1644 - suite: fix test failures by [@​stevenh](https://github.com/stevenh) in stretchr/testify#1421 - Fix issue [#​1662](stretchr/testify#1662) (comparing infs should fail) by [@​ybrustin](https://github.com/ybrustin) in stretchr/testify#1663 - NotSame should fail if args are not pointers [#​1661](stretchr/testify#1661) by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1664 - Increase timeouts in Test_Mock_Called_blocks to reduce flakiness in CI by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1667 - fix: compare functional option names for indirect calls by [@​arjun-1](
Summary
Add helper method to declare the order of the mock calls.
Changes
InOrder(calls ...*Call)
helper method to declare the order of mock calls by callingNotBefore()
Motivation
This is probably the only feature I miss from
gomock.InOrder()
, it is more intuitive and cleaner to declare the order of the mock calls. Probably most cases can be satisfied with this method.Related issues
Closes #1639