Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
all: fix generic comparisons on protobuf messages
Browse files Browse the repository at this point in the history
External counterpart of cl/282460381.

Change-Id: I1b01326214083b7d994d1b2f91bb754a6d182ca2
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/48894
Reviewed-by: kokoro <[email protected]>
Reviewed-by: Joe Tsai <[email protected]>
Reviewed-by: Tyler Bui-Palsulich <[email protected]>
  • Loading branch information
jeanbza committed Nov 26, 2019
1 parent fb261d9 commit 5721bf5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
26 changes: 20 additions & 6 deletions bigtable/bttest/inmem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
btapb "google.golang.org/genproto/googleapis/bigtable/admin/v2"
btpb "google.golang.org/genproto/googleapis/bigtable/v2"
"google.golang.org/grpc"
Expand Down Expand Up @@ -1050,8 +1049,13 @@ func TestCheckAndMutateRowWithPredicate(t *testing.T) {
// bttest for some reason undeterministically returns:
// RowStatus: &bigtable.ReadRowsResponse_CellChunk_CommitRow{CommitRow: true},
// so we'll ignore that field during comparison.
ignore := cmpopts.IgnoreFields(btpb.ReadRowsResponse_CellChunk{}, "RowStatus")
diff := cmp.Diff(gotCellChunks, wantCellChunks, ignore)
scrubRowStatus := func(cs []*btpb.ReadRowsResponse_CellChunk) []*btpb.ReadRowsResponse_CellChunk {
for _, c := range cs {
c.RowStatus = nil
}
return cs
}
diff := cmp.Diff(scrubRowStatus(gotCellChunks), scrubRowStatus(wantCellChunks), cmp.Comparer(proto.Equal))
if diff != "" {
t.Fatalf("unexpected response: %s", diff)
}
Expand Down Expand Up @@ -1146,7 +1150,17 @@ func TestServer_ReadModifyWriteRow(t *testing.T) {
},
}

diff := cmp.Diff(got, want, cmpopts.IgnoreFields(btpb.Cell{}, "TimestampMicros"))
scrubTimestamp := func(resp *btpb.ReadModifyWriteRowResponse) *btpb.ReadModifyWriteRowResponse {
for _, fam := range resp.GetRow().GetFamilies() {
for _, col := range fam.GetColumns() {
for _, cell := range col.GetCells() {
cell.TimestampMicros = 0
}
}
}
return resp
}
diff := cmp.Diff(scrubTimestamp(got), scrubTimestamp(want), cmp.Comparer(proto.Equal))
if diff != "" {
t.Errorf("unexpected response: %s", diff)
}
Expand Down Expand Up @@ -1592,7 +1606,7 @@ func TestFilterRowWithSingleColumnQualifier(t *testing.T) {
},
},
}
if diff := cmp.Diff(got, want); diff != "" {
if diff := cmp.Diff(got, want, cmp.Comparer(proto.Equal)); diff != "" {
t.Fatalf("Response mismatch: got: + want -\n%s", diff)
}
}
Expand Down Expand Up @@ -1689,7 +1703,7 @@ func TestValueFilterRowWithAlternationInRegex(t *testing.T) {
},
},
}
if diff := cmp.Diff(gotChunks, wantChunks); diff != "" {
if diff := cmp.Diff(gotChunks, wantChunks, cmp.Comparer(proto.Equal)); diff != "" {
t.Fatalf("Response chunks mismatch: got: + want -\n%s", diff)
}
}
6 changes: 5 additions & 1 deletion bigtable/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ func TestRetryApplyBulk_UnretryableErrors(t *testing.T) {
status.Errorf(codes.FailedPrecondition, ""),
status.Errorf(codes.Aborted, ""),
}
if !testutil.Equal(want, errors) {
if !testutil.Equal(want, errors,
cmp.Comparer(func(x, y error) bool {
return x == y || (x != nil && y != nil && x.Error() == y.Error())
}),
) {
t.Errorf("unretryable errors: got: %v, want: %v", errors, want)
}
}
Expand Down
2 changes: 1 addition & 1 deletion firestore/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func runTest(test *pb.Test, c *Client, srv *mockServer) error {
got, err := nSnapshots(iter, len(typedTestcase.Listen.Snapshots))
if err != nil {
return err
} else if diff := cmp.Diff(got, typedTestcase.Listen.Snapshots); diff != "" {
} else if diff := cmp.Diff(got, typedTestcase.Listen.Snapshots, cmp.Comparer(proto.Equal)); diff != "" {
return errors.New(diff)
}
if typedTestcase.Listen.IsError {
Expand Down

0 comments on commit 5721bf5

Please sign in to comment.