Skip to content

Commit f697fff

Browse files
committed
cleanup and testing
1 parent 65cefed commit f697fff

File tree

3 files changed

+96
-17
lines changed

3 files changed

+96
-17
lines changed

protocol/alterclientquotas/alterclientquotas.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ func init() {
66
protocol.Register(&Request{}, &Response{})
77
}
88

9+
// Detailed API definition: https://kafka.apache.org/protocol#The_Messages_AlterClientQuotas
910
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-
1411
Entries []Entry `kafka:"min=v0,max=v1"`
1512
ValidateOnly bool `kafka:"min=v0,max=v1"`
1613
}
@@ -26,16 +23,9 @@ type Entry struct {
2623
Ops []Ops `kafka:"min=v0,max=v1"`
2724
}
2825

29-
type EntityType string
30-
31-
const (
32-
ClientID EntityType = "client-id"
33-
User EntityType = "user"
34-
)
35-
3626
type Entity struct {
37-
EntityType EntityType `kafka:"min=v0,max=v1"`
38-
EntityName string `kafka:"min=v0,max=v1,nullable"`
27+
EntityType string `kafka:"min=v0,max=v1"`
28+
EntityName string `kafka:"min=v0,max=v1,nullable"`
3929
}
4030

4131
type Ops struct {
@@ -45,10 +35,6 @@ type Ops struct {
4535
}
4636

4737
type Response struct {
48-
// We need at least one tagged field to indicate that v2+ uses "flexible"
49-
// messages.
50-
_ struct{} `kafka:"min=v2,max=v2,tag"`
51-
5238
ThrottleTimeMs int32 `kafka:"min=v0,max=v1"`
5339
Results []ResponseQuotas `kafka:"min=v0,max=v1"`
5440
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package alterclientquotas_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/segmentio/kafka-go/protocol/alterclientquotas"
7+
"github.com/segmentio/kafka-go/protocol/prototest"
8+
)
9+
10+
const (
11+
v0 = 0
12+
v1 = 1
13+
)
14+
15+
func TestAlterClientQuotasRequest(t *testing.T) {
16+
prototest.TestRequest(t, v0, &alterclientquotas.Request{
17+
ValidateOnly: true,
18+
Entries: []alterclientquotas.Entry{
19+
alterclientquotas.Entry{
20+
Entities: []alterclientquotas.Entity{
21+
alterclientquotas.Entity{
22+
EntityType: "client-id",
23+
EntityName: "my-client-id",
24+
},
25+
},
26+
Ops: []alterclientquotas.Ops{
27+
alterclientquotas.Ops{
28+
Key: "producer_byte_rate",
29+
Value: 1.0,
30+
Remove: false,
31+
},
32+
},
33+
},
34+
},
35+
})
36+
37+
prototest.TestRequest(t, v1, &alterclientquotas.Request{
38+
ValidateOnly: true,
39+
Entries: []alterclientquotas.Entry{
40+
alterclientquotas.Entry{
41+
Entities: []alterclientquotas.Entity{
42+
alterclientquotas.Entity{
43+
EntityType: "client-id",
44+
EntityName: "my-client-id",
45+
},
46+
},
47+
Ops: []alterclientquotas.Ops{
48+
alterclientquotas.Ops{
49+
Key: "producer_byte_rate",
50+
Value: 1.0,
51+
Remove: false,
52+
},
53+
},
54+
},
55+
},
56+
})
57+
}
58+
59+
func TestAlterClientQuotasResponse(t *testing.T) {
60+
prototest.TestResponse(t, v0, &alterclientquotas.Response{
61+
ThrottleTimeMs: 500,
62+
Results: []alterclientquotas.ResponseQuotas{
63+
alterclientquotas.ResponseQuotas{
64+
ErrorCode: 1,
65+
ErrorMessage: "foo",
66+
Entities: []alterclientquotas.Entity{
67+
alterclientquotas.Entity{
68+
EntityType: "client-id",
69+
EntityName: "my-client-id",
70+
},
71+
},
72+
},
73+
},
74+
})
75+
76+
prototest.TestResponse(t, v1, &alterclientquotas.Response{
77+
ThrottleTimeMs: 500,
78+
Results: []alterclientquotas.ResponseQuotas{
79+
alterclientquotas.ResponseQuotas{
80+
ErrorCode: 1,
81+
ErrorMessage: "foo",
82+
Entities: []alterclientquotas.Entity{
83+
alterclientquotas.Entity{
84+
EntityType: "client-id",
85+
EntityName: "my-client-id",
86+
},
87+
},
88+
},
89+
},
90+
})
91+
}

protocol/prototest/prototest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func deepEqualValue(v1, v2 reflect.Value) bool {
4848
return v1.Bool() == v2.Bool()
4949
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
5050
return v1.Int() == v2.Int()
51+
case reflect.Float64:
52+
return v1.Float() == v2.Float()
5153
case reflect.String:
5254
return v1.String() == v2.String()
5355
case reflect.Struct:

0 commit comments

Comments
 (0)