MCPcopy
hub / github.com/grpc/grpc-go / TestFromContextError

Method TestFromContextError

status/status_test.go:464–482  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

462}
463
464func (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}

Callers

nothing calls this directly

Calls 6

FromContextErrorFunction · 0.85
CodeMethod · 0.80
MessageMethod · 0.80
NewFunction · 0.70
ErrorMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected