github.com/rbisecke/kafka-go@v0.4.27/offsetfetch_test.go (about)

     1  package kafka
     2  
     3  import (
     4  	"bufio"
     5  	"bytes"
     6  	"reflect"
     7  	"testing"
     8  )
     9  
    10  func TestOffsetFetchResponseV1(t *testing.T) {
    11  	item := offsetFetchResponseV1{
    12  		Responses: []offsetFetchResponseV1Response{
    13  			{
    14  				Topic: "a",
    15  				PartitionResponses: []offsetFetchResponseV1PartitionResponse{
    16  					{
    17  						Partition: 2,
    18  						Offset:    3,
    19  						Metadata:  "b",
    20  						ErrorCode: 4,
    21  					},
    22  				},
    23  			},
    24  		},
    25  	}
    26  
    27  	b := bytes.NewBuffer(nil)
    28  	w := &writeBuffer{w: b}
    29  	item.writeTo(w)
    30  
    31  	var found offsetFetchResponseV1
    32  	remain, err := (&found).readFrom(bufio.NewReader(b), b.Len())
    33  	if err != nil {
    34  		t.Error(err)
    35  		t.FailNow()
    36  	}
    37  	if remain != 0 {
    38  		t.Errorf("expected 0 remain, got %v", remain)
    39  		t.FailNow()
    40  	}
    41  	if !reflect.DeepEqual(item, found) {
    42  		t.Error("expected item and found to be the same")
    43  		t.FailNow()
    44  	}
    45  }