@@ -287,15 +287,16 @@ func Test_UnaryServerInterceptor_WithStatusCodeMap_WhenUnknownCode(t *testing.T)
287
287
}
288
288
}
289
289
290
- func Test_UnaryServerInterceptor_WithStatusCodeMap_WhenAlreadySet (t * testing.T ) {
290
+ func Test_UnaryServerInterceptor_WithGrpcStatusUnwrapper (t * testing.T ) {
291
291
code := codes .Unauthenticated
292
292
293
293
ctx := errorstesting .CreateTestContext (t )
294
294
ctx .Service = & errorWithGrpcStatusService {Code : code }
295
295
ctx .AddUnaryServerInterceptor (
296
296
UnaryServerInterceptor (
297
+ WithGrpcStatusUnwrapper (),
297
298
WithStatusCodeMap (map [int ]codes.Code {
298
- int ( code ) : codes .Aborted ,
299
+ 50 : codes .Unavailable ,
299
300
}),
300
301
),
301
302
)
@@ -319,6 +320,38 @@ func Test_UnaryServerInterceptor_WithStatusCodeMap_WhenAlreadySet(t *testing.T)
319
320
}
320
321
}
321
322
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
+
322
355
func Test_UnaryServerInterceptor_WithStatusCodeMapper (t * testing.T ) {
323
356
code := 50
324
357
mappedCode := codes .Unavailable
0 commit comments