| 1 |
|
| 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, |
| 15 |
0, 35, |
| 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, |
| 18 |
} |
| 19 |
|
| 20 |
describeClientQuotasResponseSingleValue = []byte{ |
| 21 |
0, 0, 0, 0, |
| 22 |
0, 0, |
| 23 |
255, 255, |
| 24 |
0, 0, 0, 1, |
| 25 |
0, 0, 0, 1, |
| 26 |
0, 4, 'u', 's', 'e', 'r', |
| 27 |
255, 255, |
| 28 |
0, 0, 0, 1, |
| 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, |
| 31 |
} |
| 32 |
|
| 33 |
describeClientQuotasResponseComplexEntity = []byte{ |
| 34 |
0, 0, 0, 0, |
| 35 |
0, 0, |
| 36 |
255, 255, |
| 37 |
0, 0, 0, 2, |
| 38 |
0, 0, 0, 1, |
| 39 |
0, 4, 'u', 's', 'e', 'r', |
| 40 |
255, 255, |
| 41 |
0, 0, 0, 1, |
| 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, |
| 44 |
0, 0, 0, 1, |
| 45 |
0, 9, 'c', 'l', 'i', 'e', 'n', 't', '-', 'i', 'd', |
| 46 |
0, 6, 's', 'a', 'r', 'a', 'm', 'a', |
| 47 |
0, 0, 0, 1, |
| 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, |
| 50 |
} |
| 51 |
|
| 52 |
describeClientQuotasResponseV1 = []byte{ |
| 53 |
0x00, 0x00, 0x00, 0x80, |
| 54 |
0x00, 0x00, |
| 55 |
0x01, |
| 56 |
0x02, |
| 57 |
0x02, |
| 58 |
0x05, 'u', 's', 'e', 'r', |
| 59 |
0x00, |
| 60 |
0x00, |
| 61 |
0x02, |
| 62 |
|
| 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, |
| 65 |
0x00, |
| 66 |
0x00, |
| 67 |
0x00, |
| 68 |
} |
| 69 |
) |
| 70 |
|
| 71 |
func TestDescribeClientQuotasResponse(t *testing.T) { |
| 72 |
|
| 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 |
|
| 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 |
|
| 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 |
} |