MCPcopy
hub / github.com/IBM/sarama / testRequestEncode

Function testRequestEncode

request_test.go:618–639  ·  view source on GitHub ↗
(t *testing.T, name string, rb protocolBody, expected []byte)

Source from the content-addressed store, hash-verified

616}
617
618func testRequestEncode(t *testing.T, name string, rb protocolBody, expected []byte) []byte {
619 req := &request{correlationID: 123, clientID: "foo", body: rb}
620 packet, err := encode(req, nil)
621
622 headerSize := 0
623
624 switch rb.headerVersion() {
625 case 1:
626 headerSize = 14 + len("foo")
627 case 2:
628 headerSize = 14 + len("foo") + 1
629 default:
630 t.Error("Encoding", name, "failed\nheaderVersion", rb.headerVersion(), "not implemented")
631 }
632
633 if err != nil {
634 t.Error(err)
635 } else if expected != nil && !bytes.Equal(packet[headerSize:], expected) {
636 t.Error("Encoding", name, "failed\ngot ", packet[headerSize:], "\nwant", expected)
637 }
638 return packet
639}
640
641func testRequestDecode(t *testing.T, name string, rb protocolBody, packet []byte) {
642 t.Helper()

Calls 3

encodeFunction · 0.85
headerVersionMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected