mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## 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 pattern (cmp.Diff + protocmp.Transform() + protocmp.IgnoreFields() + require.Empty). The new option extends ProtoEqual with a clean call site that infers the message type automatically. The Option func type and config struct are designed to support additional comparison options in the future without changing the ProtoEqual signature. ## How did you test it? - [X] built - [X] run locally and tested manually - [X] covered by existing tests - [X] added new unit test(s) - [ ] added new functional test(s)
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
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"
|
|
|
|
type mockT struct {
|
|
failed bool
|
|
}
|
|
|
|
func (m *mockT) Errorf(string, ...any) {
|
|
m.failed = true
|
|
}
|
|
|
|
func (m *mockT) FailNow() {
|
|
m.failed = true
|
|
}
|
|
|
|
func TestProtoEqualIgnoreFields(t *testing.T) {
|
|
a := &workflowpb.WorkflowExecutionInfo{
|
|
Execution: &commonpb.WorkflowExecution{
|
|
WorkflowId: "wf-1",
|
|
RunId: myUUID,
|
|
},
|
|
Status: 1,
|
|
TaskQueue: "queue-a",
|
|
}
|
|
b := &workflowpb.WorkflowExecutionInfo{
|
|
Execution: &commonpb.WorkflowExecution{
|
|
WorkflowId: "wf-1",
|
|
RunId: myUUID,
|
|
},
|
|
Status: 2,
|
|
TaskQueue: "queue-b",
|
|
}
|
|
|
|
t.Run("all differing fields ignored", func(t *testing.T) {
|
|
protorequire.ProtoEqual(t, a, b,
|
|
protorequire.IgnoreFields(
|
|
"status",
|
|
"task_queue",
|
|
),
|
|
)
|
|
})
|
|
|
|
t.Run("partial ignore still fails", func(t *testing.T) {
|
|
mt := &mockT{}
|
|
protorequire.ProtoEqual(mt, a, b,
|
|
protorequire.IgnoreFields(
|
|
"status",
|
|
),
|
|
)
|
|
if !mt.failed {
|
|
t.Fatal("expected comparison to fail when not all differing fields are ignored")
|
|
}
|
|
})
|
|
}
|