Skip to content

add protorequire.ProtoEqualIgnoreFields helper#9937

Open
fretz12 wants to merge 3 commits intotemporalio:mainfrom
fretz12:fredtzeng/proto-equals-ignore
Open

add protorequire.ProtoEqualIgnoreFields helper#9937
fretz12 wants to merge 3 commits intotemporalio:mainfrom
fretz12:fredtzeng/proto-equals-ignore

Conversation

@fretz12
Copy link
Copy Markdown
Contributor

@fretz12 fretz12 commented Apr 13, 2026

What changed?

Added ProtoEqualIgnoreFields to protoassert and protorequire packages. Refactored 3 call sites in standalone_activity_test.go to use the new helper.

Why?

Comparing proto messages while ignoring specific fields required a verbose 4-line pattern (cmp.Diff + protocmp.Transform() + protocmp.IgnoreFields() + require.Empty). The new helper provides a clean one-liner that's consistent with the existing protorequire.ProtoEqual API.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)


// ProtoEqualIgnoreFields compares two proto messages for equality, ignoring the specified fields on the given message
// type. Fields are specified by their proto name (snake_case).
func ProtoEqualIgnoreFields(t require.TestingT, a proto.Message, b proto.Message, msgType proto.Message, fields ...protoreflect.Name) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Food for thought.
There's some other interesting options we can potentially expose:

protocmp.SortRepeatedFields
protocmp.IgnoreEnums
cmpopts.EquateApproxTime
Also another approach is to make this a really generic function:
func ProtoEqualWithOptions(t assert.TestingT, a proto.Message, b proto.Message, opts ...cmp.Option) bool

and it can be used as such:
protorequire.ProtoEqualWithOptions(t, expected, actual, protocmp.IgnoreFields(&activitypb.ActivityExecutionInfo{}, "state_transition_count"), cmpopts.EquateApproxTime(5*time.Second), )

However, that leaks proto/cmp abstractions making the helper harder to use. I decided to make the helper focused on ignore fields, as that's our majority use case and the interface is very clean. I propose for other useful options, like EquateApproxTime, we create separate helpers. But open to thoughts

@fretz12 fretz12 marked this pull request as ready for review April 13, 2026 22:58
@fretz12 fretz12 requested review from a team as code owners April 13, 2026 22:58
@stephanos stephanos self-requested a review April 14, 2026 01:08
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