This is an automated email from the ASF dual-hosted git repository.
lostluck pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new 2a0820a8309 sdks/go: utilize go-cmp package for comparison (#33922)
2a0820a8309 is described below
commit 2a0820a8309ce5e5b04a9cab4a234cabac5f8679
Author: Mohamed Awnallah <[email protected]>
AuthorDate: Wed Feb 12 07:51:34 2025 +0200
sdks/go: utilize go-cmp package for comparison (#33922)
---
.../pkg/beam/core/runtime/exec/fullvalue_test.go | 39 ++++++++--------------
1 file changed, 13 insertions(+), 26 deletions(-)
diff --git a/sdks/go/pkg/beam/core/runtime/exec/fullvalue_test.go
b/sdks/go/pkg/beam/core/runtime/exec/fullvalue_test.go
index f8fc002d946..e0e8bbffd8d 100644
--- a/sdks/go/pkg/beam/core/runtime/exec/fullvalue_test.go
+++ b/sdks/go/pkg/beam/core/runtime/exec/fullvalue_test.go
@@ -19,12 +19,15 @@ import (
"io"
"reflect"
"testing"
+ "unicode"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/coder"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/mtime"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/window"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/reflectx"
+ "github.com/google/go-cmp/cmp"
+ "github.com/google/go-cmp/cmp/cmpopts"
)
func makeInput(vs ...any) []MainInput {
@@ -153,35 +156,19 @@ func equalList(a, b []FullValue) bool {
}
func equal(a, b FullValue) bool {
- if a.Timestamp != b.Timestamp {
- return false
- }
- if (a.Elm == nil) != (b.Elm == nil) {
- return false
- }
- if (a.Elm2 == nil) != (b.Elm2 == nil) {
- return false
- }
-
- if a.Elm != nil {
- if !reflect.DeepEqual(a.Elm, b.Elm) {
- return false
- }
- }
- if a.Elm2 != nil {
- if !reflect.DeepEqual(a.Elm2, b.Elm2) {
- return false
- }
- }
- if len(a.Windows) != len(b.Windows) {
- return false
- }
- for i, w := range a.Windows {
- if !w.Equals(b.Windows[i]) {
+ ignoreUnexportedFields := cmp.FilterPath(func(p cmp.Path) bool {
+ sf, ok := p.Index(-1).(cmp.StructField)
+ if !ok {
return false
}
+ return !unicode.IsUpper(rune(sf.Name()[0]))
+ }, cmp.Ignore())
+
+ compareOptions := []cmp.Option{
+ cmpopts.IgnoreFields(FullValue{}, "Continuation", "Pane"),
+ ignoreUnexportedFields,
}
- return true
+ return cmp.Equal(a, b, compareOptions...)
}
// Conversion tests.