File: list_groups_response_test.go

package info (click to toggle)
golang-github-ibm-sarama 1.46.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,072 kB
  • sloc: makefile: 40; sh: 30
file content (117 lines) | stat: -rw-r--r-- 3,461 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//go:build !functional

package sarama

import (
	"errors"
	"testing"
)

var (
	listGroupsResponseEmpty = []byte{
		0, 0, // no error
		0, 0, 0, 0, // no groups
	}

	listGroupsResponseError = []byte{
		0, 31, // no error
		0, 0, 0, 0, // ErrClusterAuthorizationFailed
	}

	listGroupsResponseWithConsumer = []byte{
		0, 0, // no error
		0, 0, 0, 1, // 1 group
		0, 3, 'f', 'o', 'o', // group name
		0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // protocol type
	}

	listGroupResponseV4 = []byte{
		0, 0, 0, 0, // no throttle time
		0, 0, // no error
		2,                // compact array length (1)
		4, 'f', 'o', 'o', // group name (compact string)
		9, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // protocol type (compact string)
		6, 'E', 'm', 'p', 't', 'y', // state (compact string)
		0, // Empty tag buffer
		0, // Empty tag buffer
	}

	listGroupResponseV5 = []byte{
		0, 0, 0, 0, // no throttle time
		0, 0, // no error
		2,                // compact array length (1)
		4, 'f', 'o', 'o', // group name (compact string)
		9, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // protocol type (compact string)
		6, 'E', 'm', 'p', 't', 'y', // state (compact string)
		8, 'C', 'l', 'a', 's', 's', 'i', 'c', // type (compact string)
		0, // Empty tag buffer
		0, // Empty tag buffer
	}
)

func TestListGroupsResponse(t *testing.T) {
	var response *ListGroupsResponse

	response = new(ListGroupsResponse)
	testVersionDecodable(t, "no error", response, listGroupsResponseEmpty, 0)
	if !errors.Is(response.Err, ErrNoError) {
		t.Error("Expected no gerror, found:", response.Err)
	}
	if len(response.Groups) != 0 {
		t.Error("Expected no groups")
	}

	response = new(ListGroupsResponse)
	testVersionDecodable(t, "no error", response, listGroupsResponseError, 0)
	if !errors.Is(response.Err, ErrClusterAuthorizationFailed) {
		t.Error("Expected no gerror, found:", response.Err)
	}
	if len(response.Groups) != 0 {
		t.Error("Expected no groups")
	}

	response = new(ListGroupsResponse)
	testVersionDecodable(t, "no error", response, listGroupsResponseWithConsumer, 0)
	if !errors.Is(response.Err, ErrNoError) {
		t.Error("Expected no gerror, found:", response.Err)
	}
	if len(response.Groups) != 1 {
		t.Error("Expected one group")
	}
	if response.Groups["foo"] != "consumer" {
		t.Error("Expected foo group to use consumer protocol")
	}

	response = new(ListGroupsResponse)
	testVersionDecodable(t, "no error", response, listGroupResponseV4, 4)
	if !errors.Is(response.Err, ErrNoError) {
		t.Error("Expected no gerror, found:", response.Err)
	}
	if len(response.Groups) != 1 {
		t.Error("Expected one group")
	}
	if response.Groups["foo"] != "consumer" {
		t.Error("Expected foo group to use consumer protocol")
	}
	if response.GroupsData["foo"].GroupState != "Empty" {
		t.Error("Expected foo group to have empty state")
	}

	response = new(ListGroupsResponse)
	testVersionDecodable(t, "no error", response, listGroupResponseV5, 5)
	if !errors.Is(response.Err, ErrNoError) {
		t.Error("Expected no gerror, found:", response.Err)
	}
	if len(response.Groups) != 1 {
		t.Error("Expected one group")
	}
	if response.Groups["foo"] != "consumer" {
		t.Error("Expected foo group to use consumer protocol")
	}
	if response.GroupsData["foo"].GroupState != "Empty" {
		t.Error("Expected foo group to have empty state")
	}
	if response.GroupsData["foo"].GroupType != "Classic" {
		t.Error("Expected foo group to have type 'Classic', found: ", response.GroupsData["foo"].GroupType)
	}
}