File: consumer_metadata_response_test.go

package info (click to toggle)
golang-github-shopify-sarama 1.22.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,728 kB
  • sloc: sh: 112; makefile: 43
file content (44 lines) | stat: -rw-r--r-- 1,155 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 sarama

import "testing"

var (
	consumerMetadataResponseError = []byte{
		0x00, 0x0E,
		0x00, 0x00, 0x00, 0x00,
		0x00, 0x00,
		0x00, 0x00, 0x00, 0x00}

	consumerMetadataResponseSuccess = []byte{
		0x00, 0x00,
		0x00, 0x00, 0x00, 0xAB,
		0x00, 0x03, 'f', 'o', 'o',
		0x00, 0x00, 0xCC, 0xDD}
)

func TestConsumerMetadataResponseError(t *testing.T) {
	response := &ConsumerMetadataResponse{Err: ErrOffsetsLoadInProgress}
	testEncodable(t, "", response, consumerMetadataResponseError)

	decodedResp := &ConsumerMetadataResponse{}
	if err := versionedDecode(consumerMetadataResponseError, decodedResp, 0); err != nil {
		t.Error("could not decode: ", err)
	}

	if decodedResp.Err != ErrOffsetsLoadInProgress {
		t.Errorf("got %s, want %s", decodedResp.Err, ErrOffsetsLoadInProgress)
	}
}

func TestConsumerMetadataResponseSuccess(t *testing.T) {
	broker := NewBroker("foo:52445")
	broker.id = 0xAB
	response := ConsumerMetadataResponse{
		Coordinator:     broker,
		CoordinatorID:   0xAB,
		CoordinatorHost: "foo",
		CoordinatorPort: 0xCCDD,
		Err:             ErrNoError,
	}
	testResponse(t, "success", &response, consumerMetadataResponseSuccess)
}