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

Method TestStatus_ErrorDetails

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

Source from the content-addressed store, hash-verified

304}
305
306func (s) TestStatus_ErrorDetails(t *testing.T) {
307 tests := []struct {
308 code codes.Code
309 details []protoadapt.MessageV1
310 }{
311 {
312 code: codes.NotFound,
313 details: nil,
314 },
315 {
316 code: codes.NotFound,
317 details: []protoadapt.MessageV1{
318 &epb.ResourceInfo{
319 ResourceType: "book",
320 ResourceName: "projects/1234/books/5678",
321 Owner: "User",
322 },
323 },
324 },
325 {
326 code: codes.Internal,
327 details: []protoadapt.MessageV1{
328 &epb.DebugInfo{
329 StackEntries: []string{
330 "first stack",
331 "second stack",
332 },
333 },
334 },
335 },
336 {
337 code: codes.Unavailable,
338 details: []protoadapt.MessageV1{
339 &epb.RetryInfo{
340 RetryDelay: &durationpb.Duration{Seconds: 60},
341 },
342 &epb.ResourceInfo{
343 ResourceType: "book",
344 ResourceName: "projects/1234/books/5678",
345 Owner: "User",
346 },
347 },
348 },
349 }
350
351 for _, tc := range tests {
352 s, err := New(tc.code, "").WithDetails(tc.details...)
353 if err != nil {
354 t.Fatalf("(%v).WithDetails(%+v) failed: %v", str(s), tc.details, err)
355 }
356 details := s.Details()
357 if len(details) != len(tc.details) {
358 t.Fatalf("len(s.Details()) = %d, want = %d.", len(details), len(tc.details))
359 }
360 for i := range details {
361 if !proto.Equal(details[i].(protoreflect.ProtoMessage), tc.details[i].(protoreflect.ProtoMessage)) {
362 t.Fatalf("(%v).Details()[%d] = %+v, want %+v", str(s), i, details[i], tc.details[i])
363 }

Callers

nothing calls this directly

Calls 6

WithDetailsMethod · 0.80
DetailsMethod · 0.80
NewFunction · 0.70
strFunction · 0.70
FatalfMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected