-
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 2 commits
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package protorequire_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| commonpb "go.temporal.io/api/common/v1" | ||
| workflowpb "go.temporal.io/api/workflow/v1" | ||
| "go.temporal.io/server/common/testing/protorequire" | ||
| ) | ||
|
|
||
| const myUUID = "deb7b204-b384-4fde-85c6-e5a56c42336a" | ||
|
|
||
| func TestProtoEqualIgnoreFields(t *testing.T) { | ||
| a := &workflowpb.WorkflowExecutionInfo{ | ||
| Execution: &commonpb.WorkflowExecution{ | ||
| WorkflowId: "wf-1", | ||
| RunId: myUUID, | ||
| }, | ||
| Status: 1, | ||
| } | ||
| b := &workflowpb.WorkflowExecutionInfo{ | ||
| Execution: &commonpb.WorkflowExecution{ | ||
| WorkflowId: "wf-1", | ||
| RunId: myUUID, | ||
| }, | ||
| Status: 2, // different — will be ignored | ||
| } | ||
|
|
||
| // Should pass: "status" is ignored | ||
| protorequire.ProtoEqualIgnoreFields(t, a, b, | ||
| &workflowpb.WorkflowExecutionInfo{}, | ||
| "status", | ||
| ) | ||
| } | ||
|
Contributor
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. Looks like the negative test's expected failure is leaking as the suite failure. We might need a mock for then this test can be
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. good call.. changed |
||
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.
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