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

Function equalLogEntry

binarylog/binarylog_end2end_test.go:797–822  ·  view source on GitHub ↗

equalLogEntry sorts the metadata entries by key (to compare metadata). This function is typically called with only two entries. It's written in this way so the code can be put in a for loop instead of copied twice.

(entries ...*binlogpb.GrpcLogEntry)

Source from the content-addressed store, hash-verified

795// This function is typically called with only two entries. It's written in this
796// way so the code can be put in a for loop instead of copied twice.
797func equalLogEntry(entries ...*binlogpb.GrpcLogEntry) (equal bool) {
798 for i, e := range entries {
799 // Clear out some fields we don't compare.
800 e.Timestamp = nil
801 e.CallId = 0 // CallID is global to the binary, hard to compare.
802 if h := e.GetClientHeader(); h != nil {
803 h.Timeout = nil
804 tmp := append(h.Metadata.Entry[:0], h.Metadata.Entry...)
805 h.Metadata.Entry = tmp
806 sort.Slice(h.Metadata.Entry, func(i, j int) bool { return h.Metadata.Entry[i].Key < h.Metadata.Entry[j].Key })
807 }
808 if h := e.GetServerHeader(); h != nil {
809 tmp := append(h.Metadata.Entry[:0], h.Metadata.Entry...)
810 h.Metadata.Entry = tmp
811 sort.Slice(h.Metadata.Entry, func(i, j int) bool { return h.Metadata.Entry[i].Key < h.Metadata.Entry[j].Key })
812 }
813 if h := e.GetTrailer(); h != nil {
814 sort.Slice(h.Metadata.Entry, func(i, j int) bool { return h.Metadata.Entry[i].Key < h.Metadata.Entry[j].Key })
815 }
816
817 if i > 0 && !proto.Equal(e, entries[i-1]) {
818 return false
819 }
820 }
821 return true
822}
823
824func testClientBinaryLog(t *testing.T, c *rpcConfig) error {
825 defer testSink.clear()

Callers 2

testClientBinaryLogFunction · 0.85
testServerBinaryLogFunction · 0.85

Calls 5

GetClientHeaderMethod · 0.80
GetServerHeaderMethod · 0.80
GetTrailerMethod · 0.80
SliceMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected