| 462 | } |
| 463 | |
| 464 | func (s) TestFromContextError(t *testing.T) { |
| 465 | testCases := []struct { |
| 466 | in error |
| 467 | want *Status |
| 468 | }{ |
| 469 | {in: nil, want: New(codes.OK, "")}, |
| 470 | {in: context.DeadlineExceeded, want: New(codes.DeadlineExceeded, context.DeadlineExceeded.Error())}, |
| 471 | {in: context.Canceled, want: New(codes.Canceled, context.Canceled.Error())}, |
| 472 | {in: errors.New("other"), want: New(codes.Unknown, "other")}, |
| 473 | {in: fmt.Errorf("wrapped: %w", context.DeadlineExceeded), want: New(codes.DeadlineExceeded, "wrapped: "+context.DeadlineExceeded.Error())}, |
| 474 | {in: fmt.Errorf("wrapped: %w", context.Canceled), want: New(codes.Canceled, "wrapped: "+context.Canceled.Error())}, |
| 475 | } |
| 476 | for _, tc := range testCases { |
| 477 | got := FromContextError(tc.in) |
| 478 | if got.Code() != tc.want.Code() || got.Message() != tc.want.Message() { |
| 479 | t.Errorf("FromContextError(%v) = %v; want %v", tc.in, got, tc.want) |
| 480 | } |
| 481 | } |
| 482 | } |