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

Method TestErrorIs

status/status_ext_test.go:65–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func (s) TestErrorIs(t *testing.T) {
66 // Test errors.
67 testErr := status.Error(codes.Internal, "internal server error")
68 testErrWithDetails := errWithDetails(t, status.New(codes.Internal, "internal server error"), &testpb.Empty{})
69
70 // Test cases.
71 testCases := []struct {
72 err1, err2 error
73 want bool
74 }{
75 {err1: testErr, err2: nil, want: false},
76 {err1: testErr, err2: status.Error(codes.Internal, "internal server error"), want: true},
77 {err1: testErr, err2: status.Error(codes.Internal, "internal error"), want: false},
78 {err1: testErr, err2: status.Error(codes.Unknown, "internal server error"), want: false},
79 {err1: testErr, err2: errors.New("non-grpc error"), want: false},
80 {err1: testErrWithDetails, err2: status.Error(codes.Internal, "internal server error"), want: false},
81 {err1: testErrWithDetails, err2: errWithDetails(t, status.New(codes.Internal, "internal server error"), &testpb.Empty{}), want: true},
82 {err1: testErrWithDetails, err2: errWithDetails(t, status.New(codes.Internal, "internal server error"), &testpb.Empty{}, &testpb.Empty{}), want: false},
83 }
84
85 for _, tc := range testCases {
86 isError, ok := tc.err1.(interface{ Is(target error) bool })
87 if !ok {
88 t.Errorf("(%v) does not implement is", tc.err1)
89 continue
90 }
91
92 is := isError.Is(tc.err2)
93 if is != tc.want {
94 t.Errorf("(%v).Is(%v) = %t; want %t", tc.err1, tc.err2, is, tc.want)
95 }
96 }
97}
98
99// TestStatusDetails tests how gRPC handles grpc-status-details-bin, especially
100// in cases where it doesn't match the grpc-status trailer or contains arbitrary

Callers

nothing calls this directly

Calls 5

ErrorFunction · 0.92
NewFunction · 0.92
errWithDetailsFunction · 0.85
IsMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected