-
Notifications
You must be signed in to change notification settings - Fork 1.5k
change require.protoEquals to support compare options #9937
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
Changes from 1 commit
8207153
89e4431
2c6e553
4ec2902
dc23b9c
7dde6ef
9cc3ac4
d03939d
64f0af3
7a317ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "github.com/stretchr/testify/require" | ||
| "go.temporal.io/server/common/testing/protoassert" | ||
| "google.golang.org/protobuf/proto" | ||
| "google.golang.org/protobuf/reflect/protoreflect" | ||
| ) | ||
|
|
||
| type helper interface { | ||
|
|
@@ -27,6 +28,17 @@ func ProtoEqual(t require.TestingT, a proto.Message, b proto.Message) { | |
| } | ||
| } | ||
|
|
||
| // ProtoEqualIgnoreFields compares two proto messages for equality, ignoring the specified fields | ||
| // on the given message type. Calls FailNow on mismatch. | ||
| func ProtoEqualIgnoreFields(t require.TestingT, a proto.Message, b proto.Message, msgType proto.Message, fields ...protoreflect.Name) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Food for thought. protocmp.SortRepeatedFields and it can be used as such: 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 |
||
| if th, ok := t.(helper); ok { | ||
| th.Helper() | ||
| } | ||
| if !protoassert.ProtoEqualIgnoreFields(t, a, b, msgType, fields...) { | ||
| t.FailNow() | ||
| } | ||
| } | ||
|
|
||
| func NotProtoEqual(t require.TestingT, a proto.Message, b proto.Message) { | ||
| if th, ok := t.(helper); ok { | ||
| th.Helper() | ||
|
|
@@ -83,3 +95,12 @@ func (x ProtoAssertions) ProtoElementsMatch(a any, b any) bool { | |
|
|
||
| return protoassert.ProtoElementsMatch(x.t, a, b) | ||
| } | ||
|
|
||
| func (x ProtoAssertions) ProtoEqualIgnoreFields(a proto.Message, b proto.Message, msgType proto.Message, fields ...protoreflect.Name) { | ||
| if th, ok := x.t.(helper); ok { | ||
| th.Helper() | ||
| } | ||
| if !protoassert.ProtoEqualIgnoreFields(x.t, a, b, msgType, fields...) { | ||
| x.t.FailNow() | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.