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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-07 14:52:38 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-07 14:53:13 +0300
commitf3ece0197d95d786e2b61b54ce3efad632a5720b (patch)
treed259d560a0b0d2688aef0bb7b779945540bec9b1
parentadb908088a9bf52b0d093b8ed98b7b43c3845e24 (diff)
helper: Add test to verify formatting with nested gRPC errors
Add a testcase to verify that formatting of gRPC errors works as expected with nested errors.
-rw-r--r--internal/helper/error_test.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/helper/error_test.go b/internal/helper/error_test.go
index 80b0d429e..72a5353f9 100644
--- a/internal/helper/error_test.go
+++ b/internal/helper/error_test.go
@@ -189,6 +189,23 @@ func TestErrorf(t *testing.T) {
require.True(t, ok)
require.Equal(t, status.New(codes.Unauthenticated, "top-level: rpc error: code = Unauthenticated desc = nested"), s)
})
+
+ t.Run("multi-nesting gRPC errors", func(t *testing.T) {
+ require.NotEqual(t, tc.expectedCode, codes.Unauthenticated)
+
+ err := tc.errorf("first: %w",
+ ErrInternalf("second: %w",
+ status.Error(codes.Unauthenticated, "third"),
+ ),
+ )
+ require.EqualError(t, err, "first: second: rpc error: code = Unauthenticated desc = third")
+
+ // We should be reporting the error code of the nested error.
+ require.Equal(t, codes.Unauthenticated, status.Code(err))
+ s, ok := status.FromError(err)
+ require.True(t, ok)
+ require.Equal(t, status.New(codes.Unauthenticated, "first: second: rpc error: code = Unauthenticated desc = third"), s)
+ })
})
}
}