Skip to content

feat: add support for go-cmp argument matching #1773

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IlyasYOY
Copy link

@IlyasYOY IlyasYOY commented Jul 23, 2025

Summary

Added support for Google's go-cmp library in the mock package for customizable deep comparisons during test assertions:

  • Updated go.mod to include go-cmp dependency
  • Introduced goCmpArgument type in mock/mock.go to encapsulate comparison values and options
  • Implemented GoCmp() helper function to create comparison arguments
  • Use cmp.Diff() for precise comparison output
  • Allow customization via cmp.Options

Changes

Adds new assertion behavior (not a bug fix):

  • Introduces GoCmp() as an alternative to mock.MatchedBy()
  • Enables field-level comparison customization via cmp.Option
  • Adds diff output formatting in error messages

Motivation

Support more precise comparisons than reflect.DeepEqual (e.g., ignoring specific fields)

Example usage

// Basic usage with a map
mock.On("Method", mock.GoCmp(map[string]bool{"test": true}))

// With options for unexported fields
mock.On("Method", mock.GoCmp(&ExampleType{ran: false}, cmp.AllowUnexported(ExampleType{})))

Related issues

Might relate to some issues looking for a better way to match arguments:

@IlyasYOY
Copy link
Author

This PR looks like very much like #579 (but for the mock module).

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.

1 participant