File: offsetcommit_test.go

package info (click to toggle)
golang-github-segmentio-kafka-go 0.2.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 572 kB
  • sloc: makefile: 3
file content (44 lines) | stat: -rw-r--r-- 787 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package kafka

import (
	"bufio"
	"bytes"
	"reflect"
	"testing"
)

func TestOffsetCommitResponseV2(t *testing.T) {
	item := offsetCommitResponseV2{
		Responses: []offsetCommitResponseV2Response{
			{
				Topic: "a",
				PartitionResponses: []offsetCommitResponseV2PartitionResponse{
					{
						Partition: 1,
						ErrorCode: 2,
					},
				},
			},
		},
	}

	buf := bytes.NewBuffer(nil)
	w := bufio.NewWriter(buf)
	item.writeTo(w)
	w.Flush()

	var found offsetCommitResponseV2
	remain, err := (&found).readFrom(bufio.NewReader(buf), buf.Len())
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	if remain != 0 {
		t.Errorf("expected 0 remain, got %v", remain)
		t.FailNow()
	}
	if !reflect.DeepEqual(item, found) {
		t.Error("expected item and found to be the same")
		t.FailNow()
	}
}