Debian Codegraph @

describe_client_quotas_response_test.go

raw symbols SCIP
1 //go:build !functional
2
3 package sarama
4
5 import (
6 "testing"
7 "time"
8
9 assert "github.com/stretchr/testify/require"
10 )
11
12 var (
13 describeClientQuotasResponseError = []byte{
14 0, 0, 0, 0, // ThrottleTime
15 0, 35, // ErrorCode
16 0, 41, 'C', 'u', 's', 't', 'o', 'm', ' ', 'e', 'n', 't', 'i', 't', 'y', ' ', 't', 'y', 'p', 'e', ' ', '\'', 'f', 'a', 'u', 'l', 't', 'y', '\'', ' ', 'n', 'o', 't', ' ', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd',
17 0, 0, 0, 0, // Entries
18 }
19
20 describeClientQuotasResponseSingleValue = []byte{
21 0, 0, 0, 0, // ThrottleTime
22 0, 0, // ErrorCode
23 255, 255, // ErrorMsg (nil)
24 0, 0, 0, 1, // Entries
25 0, 0, 0, 1, // Entity
26 0, 4, 'u', 's', 'e', 'r', // Entity type
27 255, 255, // Entity name (nil)
28 0, 0, 0, 1, // Values
29 0, 18, 'p', 'r', 'o', 'd', 'u', 'c', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e',
30 65, 46, 132, 128, 0, 0, 0, 0, // 1000000
31 }
32
33 describeClientQuotasResponseComplexEntity = []byte{
34 0, 0, 0, 0, // ThrottleTime
35 0, 0, // ErrorCode
36 255, 255, // ErrorMsg (nil)
37 0, 0, 0, 2, // Entries
38 0, 0, 0, 1, // Entity
39 0, 4, 'u', 's', 'e', 'r', // Entity type
40 255, 255, // Entity name (nil)
41 0, 0, 0, 1, // Values
42 0, 18, 'p', 'r', 'o', 'd', 'u', 'c', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e',
43 65, 46, 132, 128, 0, 0, 0, 0, // 1000000
44 0, 0, 0, 1, // Entity
45 0, 9, 'c', 'l', 'i', 'e', 'n', 't', '-', 'i', 'd', // Entity type
46 0, 6, 's', 'a', 'r', 'a', 'm', 'a', // Entity name
47 0, 0, 0, 1, // Values
48 0, 18, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e',
49 65, 46, 132, 128, 0, 0, 0, 0, // 1000000
50 }
51
52 describeClientQuotasResponseV1 = []byte{
53 0x00, 0x00, 0x00, 0x80, // ThrottleTime (128ms)
54 0x00, 0x00, // ErrorCode
55 0x01, // ErrorMsg (nil)
56 0x02, // Entries (2)
57 0x02,
58 0x05, 'u', 's', 'e', 'r', // Entity Type
59 0x00, // Entity Name (nil)
60 0x00, // Empty tagged fields
61 0x02,
62 // 0x13, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x65, 0x72, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x5f, 0x72, 0x61, 0x74, 0x65,
63 0x13, 'p', 'r', 'o', 'd', 'u', 'c', 'e', 'r', '_', 'b', 'y', 't', 'e', '_', 'r', 'a', 't', 'e',
64 0x41, 0x2f, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, // 1024000
65 0x00, // Empty tagged fields
66 0x00, // Empty tagged fields
67 0x00, // Empty tagged fields
68 }
69 )
70
71 func TestDescribeClientQuotasResponse(t *testing.T) {
72 // Response With Error
73 errMsg := "Custom entity type 'faulty' not supported"
74 res := &DescribeClientQuotasResponse{
75 ThrottleTime: 0,
76 ErrorCode: ErrUnsupportedVersion,
77 ErrorMsg: &errMsg,
78 Entries: []DescribeClientQuotasEntry{},
79 }
80 testResponse(t, "Response With Error", res, describeClientQuotasResponseError)
81
82 // Single Quota entry
83 defaultUserComponent := QuotaEntityComponent{
84 EntityType: QuotaEntityUser,
85 MatchType: QuotaMatchDefault,
86 }
87 entry := DescribeClientQuotasEntry{
88 Entity: []QuotaEntityComponent{defaultUserComponent},
89 Values: map[string]float64{"producer_byte_rate": 1000000},
90 }
91 res = &DescribeClientQuotasResponse{
92 ThrottleTime: 0,
93 ErrorCode: ErrNoError,
94 ErrorMsg: nil,
95 Entries: []DescribeClientQuotasEntry{entry},
96 }
97 testResponse(t, "Single Value", res, describeClientQuotasResponseSingleValue)
98
99 // Complex Quota entry
100 saramaClientIDComponent := QuotaEntityComponent{
101 EntityType: QuotaEntityClientID,
102 MatchType: QuotaMatchExact,
103 Name: "sarama",
104 }
105 userEntry := DescribeClientQuotasEntry{
106 Entity: []QuotaEntityComponent{defaultUserComponent},
107 Values: map[string]float64{"producer_byte_rate": 1000000},
108 }
109 clientEntry := DescribeClientQuotasEntry{
110 Entity: []QuotaEntityComponent{saramaClientIDComponent},
111 Values: map[string]float64{"consumer_byte_rate": 1000000},
112 }
113 res = &DescribeClientQuotasResponse{
114 ThrottleTime: 0,
115 ErrorCode: ErrNoError,
116 ErrorMsg: nil,
117 Entries: []DescribeClientQuotasEntry{userEntry, clientEntry},
118 }
119 testResponse(t, "Complex Quota", res, describeClientQuotasResponseComplexEntity)
120 }
121
122 func TestDescribeClientQuotasResponseV1(t *testing.T) {
123 res := &DescribeClientQuotasResponse{Version: 1}
124 testVersionDecodable(t, "V1", res, describeClientQuotasResponseV1, 1)
125 assert.Equal(t, time.Millisecond*128, res.ThrottleTime)
126 assert.Len(t, res.Entries, 1)
127 assert.Equal(t, []DescribeClientQuotasEntry{
128 {
129 Entity: []QuotaEntityComponent{
130 {
131 EntityType: "user",
132 MatchType: 1,
133 },
134 },
135 Values: map[string]float64{
136 "producer_byte_rate": 1024000,
137 },
138 },
139 }, res.Entries)
140 }