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

Function testResponse

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

Source from the content-addressed store, hash-verified

655}
656
657func testResponse(t *testing.T, name string, res protocolBody, expected []byte) {
658 t.Helper()
659 encoded, err := encode(res, nil)
660 if err != nil {
661 t.Error(err)
662 } else if expected != nil && !bytes.Equal(encoded, expected) {
663 t.Error("Encoding", name, "failed\ngot ", encoded, "\nwant", expected)
664 }
665
666 decoded := reflect.New(reflect.TypeOf(res).Elem()).Interface().(versionedDecoder)
667 if err := versionedDecode(encoded, decoded, res.version(), nil); err != nil {
668 t.Error("Decoding", name, "failed:", err)
669 }
670
671 if !reflect.DeepEqual(decoded, res) {
672 t.Errorf("Decoded response does not match the encoded one\nencoded: %#v\ndecoded: %#v", res, decoded)
673 }
674}
675
676func TestDecodeRequestErrorReturns(t *testing.T) {
677 _, bytesRead, err := decodeRequest(bytes.NewReader([]byte{0, 0, 0}))

Calls 6

encodeFunction · 0.85
versionedDecodeFunction · 0.85
HelperMethod · 0.80
ErrorMethod · 0.65
versionMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected