forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
describeacls_test.go
88 lines (78 loc) · 2 KB
/
describeacls_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
package kafka
import (
"context"
"testing"
ktesting "github.com/segmentio/kafka-go/testing"
"github.com/stretchr/testify/assert"
)
func TestClientDescribeACLs(t *testing.T) {
if !ktesting.KafkaIsAtLeast("2.0.1") {
return
}
client, shutdown := newLocalClient()
defer shutdown()
topic := makeTopic()
group := makeGroupID()
createRes, err := client.CreateACLs(context.Background(), &CreateACLsRequest{
ACLs: []ACLEntry{
{
Principal: "User:alice",
PermissionType: ACLPermissionTypeAllow,
Operation: ACLOperationTypeRead,
ResourceType: ResourceTypeTopic,
ResourcePatternType: PatternTypeLiteral,
ResourceName: topic,
Host: "*",
},
{
Principal: "User:bob",
PermissionType: ACLPermissionTypeAllow,
Operation: ACLOperationTypeRead,
ResourceType: ResourceTypeGroup,
ResourcePatternType: PatternTypeLiteral,
ResourceName: group,
Host: "*",
},
},
})
if err != nil {
t.Fatal(err)
}
for _, err := range createRes.Errors {
if err != nil {
t.Error(err)
}
}
describeResp, err := client.DescribeACLs(context.Background(), &DescribeACLsRequest{
Filter: ACLFilter{
ResourceTypeFilter: ResourceTypeTopic,
ResourceNameFilter: topic,
ResourcePatternTypeFilter: PatternTypeLiteral,
Operation: ACLOperationTypeRead,
PermissionType: ACLPermissionTypeAllow,
},
})
if err != nil {
t.Fatal(err)
}
expectedDescribeResp := DescribeACLsResponse{
Throttle: 0,
Error: makeError(0, ""),
Resources: []ACLResource{
{
ResourceType: ResourceTypeTopic,
ResourceName: topic,
PatternType: PatternTypeLiteral,
ACLs: []ACLDescription{
{
Principal: "User:alice",
Host: "*",
Operation: ACLOperationTypeRead,
PermissionType: ACLPermissionTypeAllow,
},
},
},
},
}
assert.Equal(t, expectedDescribeResp, *describeResp)
}