@@ -287,15 +287,16 @@ func Test_UnaryServerInterceptor_WithStatusCodeMap_WhenUnknownCode(t *testing.T)
287287 }
288288}
289289
290- func Test_UnaryServerInterceptor_WithStatusCodeMap_WhenAlreadySet (t * testing.T ) {
290+ func Test_UnaryServerInterceptor_WithGrpcStatusUnwrapper (t * testing.T ) {
291291 code := codes .Unauthenticated
292292
293293 ctx := errorstesting .CreateTestContext (t )
294294 ctx .Service = & errorWithGrpcStatusService {Code : code }
295295 ctx .AddUnaryServerInterceptor (
296296 UnaryServerInterceptor (
297+ WithGrpcStatusUnwrapper (),
297298 WithStatusCodeMap (map [int ]codes.Code {
298- int ( code ) : codes .Aborted ,
299+ 50 : codes .Unavailable ,
299300 }),
300301 ),
301302 )
@@ -319,6 +320,38 @@ func Test_UnaryServerInterceptor_WithStatusCodeMap_WhenAlreadySet(t *testing.T)
319320 }
320321}
321322
323+ func Test_UnaryServerInterceptor_WithGrpcStatusUnwrapper_WithoutGrpcStatus (t * testing.T ) {
324+ code := 50
325+ ctx := errorstesting .CreateTestContext (t )
326+ ctx .Service = & errorWithStatusService {Code : code }
327+ ctx .AddUnaryServerInterceptor (
328+ UnaryServerInterceptor (
329+ WithGrpcStatusUnwrapper (),
330+ WithStatusCodeMap (map [int ]codes.Code {
331+ code : codes .Unauthenticated ,
332+ }),
333+ ),
334+ )
335+ ctx .Setup ()
336+ defer ctx .Teardown ()
337+
338+ resp , err := ctx .Client .EmptyCall (context .Background (), & errorstesting.Empty {})
339+
340+ if resp != nil {
341+ t .Error ("The request should not return any responses" )
342+ }
343+
344+ if err == nil {
345+ t .Error ("The request should return an error" )
346+ }
347+
348+ if st , ok := status .FromError (err ); ! ok {
349+ t .Error ("Returned error should has status code" )
350+ } else if got , want := st .Code (), codes .Unauthenticated ; got != want {
351+ t .Errorf ("Returned error had status code %v, want %v" , got , want )
352+ }
353+ }
354+
322355func Test_UnaryServerInterceptor_WithStatusCodeMapper (t * testing.T ) {
323356 code := 50
324357 mappedCode := codes .Unavailable
0 commit comments