12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package sarama
- import (
- "bytes"
- "testing"
- )
- var (
- requestSimple = []byte{
- 0x00, 0x00, 0x00, 0x17,
- 0x06, 0x66,
- 0x00, 0xD2,
- 0x00, 0x00, 0x12, 0x34,
- 0x00, 0x08, 'm', 'y', 'C', 'l', 'i', 'e', 'n', 't',
- 0x00, 0x03, 'a', 'b', 'c'}
- )
- type testRequestBody struct {
- }
- func (s *testRequestBody) key() int16 {
- return 0x666
- }
- func (s *testRequestBody) version() int16 {
- return 0xD2
- }
- func (s *testRequestBody) encode(pe packetEncoder) error {
- return pe.putString("abc")
- }
- func TestRequest(t *testing.T) {
- request := request{correlationID: 0x1234, id: "myClient", body: new(testRequestBody)}
- testEncodable(t, "simple", &request, requestSimple)
- }
- func testEncodable(t *testing.T, name string, in encoder, expect []byte) {
- packet, err := encode(in)
- if err != nil {
- t.Error(err)
- } else if !bytes.Equal(packet, expect) {
- t.Error("Encoding", name, "failed\ngot ", packet, "\nwant", expect)
- }
- }
- func testDecodable(t *testing.T, name string, out decoder, in []byte) {
- err := decode(in, out)
- if err != nil {
- t.Error("Decoding", name, "failed:", err)
- }
- }
|