forked from IBM/sarama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alter_client_quotas_response_test.go
94 lines (85 loc) · 2.8 KB
/
alter_client_quotas_response_test.go
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
package sarama
import "testing"
var (
alterClientQuotasResponseError = []byte{
0, 0, 0, 0, // ThrottleTime
0, 0, 0, 1, // Entries len
0, 42, // ErrorCode (ErrInvalidRequest)
0, 42, 'U', 'n', 'h', 'a', 'n', 'd', 'l', 'e', 'd', ' ', 'c', 'l', 'i', 'e', 'n', 't', ' ', 'q', 'u', 'o', 't', 'a', ' ', 'e', 'n', 't', 'i', 't', 'y', ' ', 't', 'y', 'p', 'e', ':', ' ', 'f', 'a', 'u', 'l', 't', 'y', // ErrorMsg
0, 0, 0, 1, // Entity len
0, 6, 'f', 'a', 'u', 'l', 't', 'y', // entityType
255, 255, // entityName
}
alterClientQuotasResponseSingleEntry = []byte{
0, 0, 0, 0, // ThrottleTime
0, 0, 0, 1, // Entries len
0, 0, // ErrorCode
255, 255, // ErrorMsg
0, 0, 0, 1, // Entity len
0, 4, 'u', 's', 'e', 'r', // entityType
255, 255, // entityName
}
alterClientQuotasResponseMultipleEntries = []byte{
0, 0, 0, 0, // ThrottleTime
0, 0, 0, 2, // Entries len
0, 0, // ErrorCode
255, 255, // ErrorMsg
0, 0, 0, 1, // Entity len
0, 4, 'u', 's', 'e', 'r', // entityType
255, 255, // entityName
0, 0, // ErrorCode
255, 255, // ErrorMsg
0, 0, 0, 1, // Entity len
0, 9, 'c', 'l', 'i', 'e', 'n', 't', '-', 'i', 'd', // entityType
255, 255, // entityName
}
)
func TestAlterClientQuotasResponse(t *testing.T) {
// default user
defaultUserComponent := QuotaEntityComponent{
EntityType: QuotaEntityUser,
MatchType: QuotaMatchDefault,
}
// default client-id
defaultClientIDComponent := QuotaEntityComponent{
EntityType: QuotaEntityClientID,
MatchType: QuotaMatchDefault,
}
// Response with error
errMsg := "Unhandled client quota entity type: faulty"
faultEntityComponent := QuotaEntityComponent{
EntityType: QuotaEntityType("faulty"),
MatchType: QuotaMatchDefault,
}
entry := AlterClientQuotasEntryResponse{
ErrorCode: KError(42),
ErrorMsg: &errMsg,
Entity: []QuotaEntityComponent{faultEntityComponent},
}
res := &AlterClientQuotasResponse{
ThrottleTime: 0,
Entries: []AlterClientQuotasEntryResponse{entry},
}
testResponse(t, "Response With Error", res, alterClientQuotasResponseError)
// Response Altered single entry
entry = AlterClientQuotasEntryResponse{
Entity: []QuotaEntityComponent{defaultUserComponent},
}
res = &AlterClientQuotasResponse{
ThrottleTime: 0,
Entries: []AlterClientQuotasEntryResponse{entry},
}
testResponse(t, "Altered single entry", res, alterClientQuotasResponseSingleEntry)
// Response Altered multiple entries
entry1 := AlterClientQuotasEntryResponse{
Entity: []QuotaEntityComponent{defaultUserComponent},
}
entry2 := AlterClientQuotasEntryResponse{
Entity: []QuotaEntityComponent{defaultClientIDComponent},
}
res = &AlterClientQuotasResponse{
ThrottleTime: 0,
Entries: []AlterClientQuotasEntryResponse{entry1, entry2},
}
testResponse(t, "Altered multiple entries", res, alterClientQuotasResponseMultipleEntries)
}