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

Method TestCallCredsFromDialOptionsStatusCodes

test/control_plane_status_test.go:150–191  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

148}
149
150func (s) TestCallCredsFromDialOptionsStatusCodes(t *testing.T) {
151 testCases := []struct {
152 name string
153 credsErr error
154 want error
155 }{{
156 name: "legal status code",
157 credsErr: status.Errorf(codes.Unavailable, "this error is fine"),
158 want: status.Errorf(codes.Unavailable, "this error is fine"),
159 }, {
160 name: "illegal status code",
161 credsErr: status.Errorf(codes.NotFound, "this error is bad"),
162 want: status.Errorf(codes.Internal, "this error is bad"),
163 }}
164
165 for _, tc := range testCases {
166 t.Run(tc.name, func(t *testing.T) {
167 ss := &stubserver.StubServer{
168 EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) {
169 return &testpb.Empty{}, nil
170 },
171 }
172
173 errChan := make(chan error, 1)
174 creds := &testPerRPCCredentials{errChan: errChan}
175
176 if err := ss.Start(nil, grpc.WithPerRPCCredentials(creds)); err != nil {
177 t.Fatalf("Error starting endpoint server: %v", err)
178 }
179 defer ss.Stop()
180
181 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
182 defer cancel()
183
184 errChan <- tc.credsErr
185
186 if _, err := ss.Client.EmptyCall(ctx, &testpb.Empty{}); status.Code(err) != status.Code(tc.want) || !strings.Contains(err.Error(), status.Convert(tc.want).Message()) {
187 t.Fatalf("client.EmptyCall(_, _) = _, %v; want _, %v", err, tc.want)
188 }
189 })
190 }
191}
192
193func (s) TestCallCredsFromCallOptionsStatusCodes(t *testing.T) {
194 testCases := []struct {

Callers

nothing calls this directly

Calls 10

StartMethod · 0.95
StopMethod · 0.95
ErrorfFunction · 0.92
WithPerRPCCredentialsFunction · 0.92
CodeFunction · 0.92
ConvertFunction · 0.92
MessageMethod · 0.80
FatalfMethod · 0.65
EmptyCallMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected