Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarthik Nayak <knayak@gitlab.com>2023-12-13 21:23:23 +0300
committerKarthik Nayak <knayak@gitlab.com>2023-12-19 11:50:56 +0300
commit46a35cfe7ef5bb9c6e8eb80c308b3885327a379a (patch)
treea71366d7a76c79fe4fa67c9b653d1ec50ab76383
parent311f6768dc9ec588d75fb4564436b1138742cb88 (diff)
testhelper: Add goroutine safe `ProtoEqualAssert`
We currently have `ProtoEqual`, which compares two proto structs. This function uses the `require` package. The require package though is not goroutine safe since it uses `t.FailNow()`. So introduce a similar `ProtoEqualAssert()` which uses the `assert` package. This is safe to use in goroutines.
-rw-r--r--internal/testhelper/grpc.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/internal/testhelper/grpc.go b/internal/testhelper/grpc.go
index 7a89eb571..24e375250 100644
--- a/internal/testhelper/grpc.go
+++ b/internal/testhelper/grpc.go
@@ -44,10 +44,20 @@ func (mockServerTransportStream) SetTrailer(md metadata.MD) error { return nil }
func ProtoEqual(tb testing.TB, expected, actual interface{}, opts ...cmp.Option) {
tb.Helper()
+ ProtoEqualAssert(tb, expected, actual, opts...)
+ if tb.Failed() {
+ tb.FailNow()
+ }
+}
+
+// ProtoEqualAssert is similar to ProtoEqual but safe to use in goroutines.
+func ProtoEqualAssert(tb testing.TB, expected, actual interface{}, opts ...cmp.Option) {
+ tb.Helper()
+
opts = append(opts, protocmp.Transform(), cmpopts.EquateErrors())
diff := cmp.Diff(expected, actual, opts...)
if len(diff) > 0 {
- require.Fail(tb, fmt.Sprintf("Protobufs not equal\nDiff: %v", diff))
+ assert.Fail(tb, fmt.Sprintf("Protobufs not equal\nDiff: %v", diff))
}
}