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 mock.ElementsMatch argument matcher #1347

Closed

Conversation

brackendawson
Copy link
Collaborator

@brackendawson brackendawson commented Feb 11, 2023

Summary

Add an argument marcher to mock which matches if array/slice elements match.

Changes

  • Add mock.ElementsMatch() argument matcher.
  • Refactor mock.argumentMatcher to be an interface, it pretty much already was.
  • Move common code used by both assert and mock into an internal package.

Motivation

There is already mock.MatchedBy which allows users to write this themselves, but it's not trivial and a lot of people seem to need this specific matcher.

func TestIfy(t *testing.T) {
	m := &myMock{}
	m.On("Do", mock.ElementsMatch([]int{1, 2, 3})).Return()
	m.Do([]int{2, 3, 1})
}

Related issues

Closes #1117
Closes #1180

- Refactor argumentMatcher to be an interface.
- Refactor move code common to assert and mock into internal package.
@dolmen dolmen added enhancement pkg-mock Any issues related to Mock labels Jul 5, 2023
@dolmen
Copy link
Collaborator

dolmen commented Jul 5, 2023

This MR includes changes to use internal/check. They are unrelated to the description of this issue. Please makes those changes available in a separate MR.

@brackendawson
Copy link
Collaborator Author

@dolmen done in #1431, this will need rebasing somewhat after that is merged.

@brackendawson brackendawson marked this pull request as draft February 24, 2024 19:45
@dolmen dolmen added the mock.ArgumentMatcher About matching arguments in mock label Mar 22, 2024
@dolmen
Copy link
Collaborator

dolmen commented Mar 22, 2024

We must first cleanup the argument matching API. See my proposal in #1578.

It is also too early to merge #1431: we have plenty of pending patches in the queue that would be broken by #1431, so I would like that we review everything before such a major refactor.

In light of this, I think that this implementation is not useful at this point, so I'm closing the issue. Could you instead open an issue with an API proposal that would fit #1578?

@dolmen dolmen closed this Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement mock.ArgumentMatcher About matching arguments in mock pkg-mock Any issues related to Mock
Projects
None yet
2 participants