MCPcopy
hub / github.com/segmentio/kafka-go / TestRequestWithOverride

Function TestRequestWithOverride

protocol/prototest/request.go:51–80  ·  view source on GitHub ↗

TestRequestWithOverride validates requests that have an overridden type. For requests with type overrides, we double-serialize the request to ensure the resulting encoding of the overridden and original type are identical.

(t *testing.T, version int16, msg protocol.Message)

Source from the content-addressed store, hash-verified

49// TestRequestWithOverride validates requests that have an overridden type. For requests with type overrides, we
50// double-serialize the request to ensure the resulting encoding of the overridden and original type are identical.
51func TestRequestWithOverride(t *testing.T, version int16, msg protocol.Message) {
52 reset := load(msg)
53
54 t.Run(fmt.Sprintf("v%d", version), func(t *testing.T) {
55 b1 := &bytes.Buffer{}
56
57 if err := protocol.WriteRequest(b1, version, 1234, "me", msg); err != nil {
58 t.Fatal(err)
59 }
60
61 reset()
62 t.Logf("\n%s\n", hex.Dump(b1.Bytes()))
63
64 _, _, _, req, err := protocol.ReadRequest(b1)
65 if err != nil {
66 t.Fatal(err)
67 }
68
69 b2 := &bytes.Buffer{}
70 if err := protocol.WriteRequest(b2, version, 1234, "me", req); err != nil {
71 t.Fatal(err)
72 }
73
74 if !deepEqual(b1, b2) {
75 t.Errorf("request message mismatch:")
76 t.Logf("expected: %+v", hex.Dump(b1.Bytes()))
77 t.Logf("found: %+v", hex.Dump(b2.Bytes()))
78 }
79 })
80}
81
82func BenchmarkRequest(b *testing.B, version int16, msg protocol.Message) {
83 reset := load(msg)

Callers 1

TestRawProduceRequestFunction · 0.92

Calls 5

WriteRequestFunction · 0.92
ReadRequestFunction · 0.92
loadFunction · 0.85
deepEqualFunction · 0.85
BytesMethod · 0.65

Tested by

no test coverage detected