Skip to content

Commit 7450047

Browse files
committed
describeclientquotas protocol cleanup and tests
1 parent 13ba79e commit 7450047

File tree

2 files changed

+89
-9
lines changed

2 files changed

+89
-9
lines changed

protocol/describeclientquotas/describeclientquotas.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ func init() {
77
}
88

99
type Request struct {
10-
// We need at least one tagged field to indicate that v2+ uses "flexible"
11-
// messages.
12-
_ struct{} `kafka:"min=v2,max=v2,tag"`
13-
1410
Components []Component `kafka:"min=v0,max=v1"`
15-
Strict boolean `kafka:"min=v0,max=v1"`
11+
Strict bool `kafka:"min=v0,max=v1"`
1612
}
1713

1814
func (r *Request) ApiKey() protocol.ApiKey { return protocol.DescribeClientQuotas }
@@ -28,10 +24,6 @@ type Component struct {
2824
}
2925

3026
type Response struct {
31-
// We need at least one tagged field to indicate that v2+ uses "flexible"
32-
// messages.
33-
_ struct{} `kafka:"min=v2,max=v2,tag"`
34-
3527
ThrottleTimeMs int32 `kafka:"min=v0,max=v1"`
3628
ErrorCode int16 `kafka:"min=v0,max=v1"`
3729
ErrorMessage string `kafka:"min=v0,max=v1,nullable"`
@@ -40,6 +32,11 @@ type Response struct {
4032

4133
func (r *Response) ApiKey() protocol.ApiKey { return protocol.DescribeClientQuotas }
4234

35+
type Entity struct {
36+
EntityType string `kafka:"min=v0,max=v1"`
37+
EntityName string `kafka:"min=v0,max=v1,nullable"`
38+
}
39+
4340
type Value struct {
4441
Key string `kafka:"min=v0,max=v1"`
4542
Value float64 `kafka:"min=v0,max=v1"`
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package describeclientquotas_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/segmentio/kafka-go/protocol/describeclientquotas"
7+
"github.com/segmentio/kafka-go/protocol/prototest"
8+
)
9+
10+
const (
11+
v0 = 0
12+
v1 = 1
13+
)
14+
15+
func TestDescribeClientQuotasRequest(t *testing.T) {
16+
prototest.TestRequest(t, v0, &describeclientquotas.Request{
17+
Strict: true,
18+
Components: []describeclientquotas.Component{
19+
describeclientquotas.Component{
20+
EntityType: "client-id",
21+
MatchType: 0,
22+
Match: "my-client-id",
23+
},
24+
},
25+
})
26+
27+
prototest.TestRequest(t, v1, &describeclientquotas.Request{
28+
Strict: true,
29+
Components: []describeclientquotas.Component{
30+
describeclientquotas.Component{
31+
EntityType: "client-id",
32+
MatchType: 0,
33+
Match: "my-client-id",
34+
},
35+
},
36+
})
37+
}
38+
39+
func TestDescribeClientQuotasResponse(t *testing.T) {
40+
prototest.TestResponse(t, v0, &describeclientquotas.Response{
41+
ThrottleTimeMs: 1,
42+
ErrorCode: 1,
43+
ErrorMessage: "foo",
44+
Entries: []describeclientquotas.ResponseQuotas{
45+
describeclientquotas.ResponseQuotas{
46+
Entities: []describeclientquotas.Entity{
47+
describeclientquotas.Entity{
48+
EntityType: "client-id",
49+
EntityName: "my-client-id",
50+
},
51+
},
52+
Values: []describeclientquotas.Value{
53+
describeclientquotas.Value{
54+
Key: "foo",
55+
Value: 1.0,
56+
},
57+
},
58+
},
59+
},
60+
})
61+
62+
prototest.TestResponse(t, v1, &describeclientquotas.Response{
63+
ThrottleTimeMs: 1,
64+
ErrorCode: 1,
65+
ErrorMessage: "foo",
66+
Entries: []describeclientquotas.ResponseQuotas{
67+
describeclientquotas.ResponseQuotas{
68+
Entities: []describeclientquotas.Entity{
69+
describeclientquotas.Entity{
70+
EntityType: "client-id",
71+
EntityName: "my-client-id",
72+
},
73+
},
74+
Values: []describeclientquotas.Value{
75+
describeclientquotas.Value{
76+
Key: "foo",
77+
Value: 1.0,
78+
},
79+
},
80+
},
81+
},
82+
})
83+
}

0 commit comments

Comments
 (0)