forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteacls_test.go
113 lines (99 loc) · 2.69 KB
/
deleteacls_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package kafka
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
ktesting "github.com/streamdal/segmentio-kafka-go/testing"
)
func TestClientDeleteACLs(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)
}
}
deleteResp, err := client.DeleteACLs(context.Background(), &DeleteACLsRequest{
Filters: []DeleteACLsFilter{
{
ResourceTypeFilter: ResourceTypeTopic,
ResourceNameFilter: topic,
ResourcePatternTypeFilter: PatternTypeLiteral,
Operation: ACLOperationTypeRead,
PermissionType: ACLPermissionTypeAllow,
},
},
})
if err != nil {
t.Fatal(err)
}
expectedDeleteResp := DeleteACLsResponse{
Throttle: 0,
Results: []DeleteACLsResult{
{
Error: makeError(0, ""),
MatchingACLs: []DeleteACLsMatchingACLs{
{
Error: makeError(0, ""),
ResourceType: ResourceTypeTopic,
ResourceName: topic,
ResourcePatternType: PatternTypeLiteral,
Principal: "User:alice",
Host: "*",
Operation: ACLOperationTypeRead,
PermissionType: ACLPermissionTypeAllow,
},
},
},
},
}
assert.Equal(t, expectedDeleteResp, *deleteResp)
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{},
}
assert.Equal(t, expectedDescribeResp, *describeResp)
}