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

Function checkInHeader

stats/stats_test.go:484–539  ·  view source on GitHub ↗
(t *testing.T, d *gotData, e *expectedData)

Source from the content-addressed store, hash-verified

482}
483
484func checkInHeader(t *testing.T, d *gotData, e *expectedData) {
485 var (
486 ok bool
487 st *stats.InHeader
488 )
489 if st, ok = d.s.(*stats.InHeader); !ok {
490 t.Fatalf("got %T, want InHeader", d.s)
491 }
492 if d.ctx == nil {
493 t.Fatalf("d.ctx = nil, want <non-nil>")
494 }
495 if st.Compression != e.compression {
496 t.Fatalf("st.Compression = %v, want %v", st.Compression, e.compression)
497 }
498 if d.client {
499 // additional headers might be injected so instead of testing equality, test that all the
500 // expected headers keys have the expected header values.
501 for key := range testHeaderMetadata {
502 if !reflect.DeepEqual(st.Header.Get(key), testHeaderMetadata.Get(key)) {
503 t.Fatalf("st.Header[%s] = %v, want %v", key, st.Header.Get(key), testHeaderMetadata.Get(key))
504 }
505 }
506 } else {
507 if st.FullMethod != e.method {
508 t.Fatalf("st.FullMethod = %s, want %v", st.FullMethod, e.method)
509 }
510 if st.LocalAddr.String() != e.serverAddr {
511 t.Fatalf("st.LocalAddr = %v, want %v", st.LocalAddr, e.serverAddr)
512 }
513 // additional headers might be injected so instead of testing equality, test that all the
514 // expected headers keys have the expected header values.
515 for key := range testMetadata {
516 if !reflect.DeepEqual(st.Header.Get(key), testMetadata.Get(key)) {
517 t.Fatalf("st.Header[%s] = %v, want %v", key, st.Header.Get(key), testMetadata.Get(key))
518 }
519 }
520
521 if connInfo, ok := d.ctx.Value(connCtxKey{}).(*stats.ConnTagInfo); ok {
522 if connInfo.RemoteAddr != st.RemoteAddr {
523 t.Fatalf("connInfo.RemoteAddr = %v, want %v", connInfo.RemoteAddr, st.RemoteAddr)
524 }
525 if connInfo.LocalAddr != st.LocalAddr {
526 t.Fatalf("connInfo.LocalAddr = %v, want %v", connInfo.LocalAddr, st.LocalAddr)
527 }
528 } else {
529 t.Fatalf("got context %v, want one with connCtxKey", d.ctx)
530 }
531 if rpcInfo, ok := d.ctx.Value(rpcCtxKey{}).(*stats.RPCTagInfo); ok {
532 if rpcInfo.FullMethodName != st.FullMethod {
533 t.Fatalf("rpcInfo.FullMethod = %s, want %v", rpcInfo.FullMethodName, st.FullMethod)
534 }
535 } else {
536 t.Fatalf("got context %v, want one with rpcCtxKey", d.ctx)
537 }
538 }
539}
540
541func checkInPayload(t *testing.T, d *gotData, e *expectedData) {

Callers

nothing calls this directly

Calls 4

FatalfMethod · 0.65
GetMethod · 0.65
StringMethod · 0.65
ValueMethod · 0.45

Tested by

no test coverage detected