github.com/segmentio/kafka-go@v0.4.48-0.20240318174348-3f6244eb34fd/describeacls_test.go (about) 1 package kafka 2 3 import ( 4 "context" 5 "testing" 6 7 ktesting "github.com/segmentio/kafka-go/testing" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestClientDescribeACLs(t *testing.T) { 12 if !ktesting.KafkaIsAtLeast("2.0.1") { 13 return 14 } 15 16 client, shutdown := newLocalClient() 17 defer shutdown() 18 19 topic := makeTopic() 20 group := makeGroupID() 21 22 createRes, err := client.CreateACLs(context.Background(), &CreateACLsRequest{ 23 ACLs: []ACLEntry{ 24 { 25 Principal: "User:alice", 26 PermissionType: ACLPermissionTypeAllow, 27 Operation: ACLOperationTypeRead, 28 ResourceType: ResourceTypeTopic, 29 ResourcePatternType: PatternTypeLiteral, 30 ResourceName: topic, 31 Host: "*", 32 }, 33 { 34 Principal: "User:bob", 35 PermissionType: ACLPermissionTypeAllow, 36 Operation: ACLOperationTypeRead, 37 ResourceType: ResourceTypeGroup, 38 ResourcePatternType: PatternTypeLiteral, 39 ResourceName: group, 40 Host: "*", 41 }, 42 }, 43 }) 44 if err != nil { 45 t.Fatal(err) 46 } 47 48 for _, err := range createRes.Errors { 49 if err != nil { 50 t.Error(err) 51 } 52 } 53 54 describeResp, err := client.DescribeACLs(context.Background(), &DescribeACLsRequest{ 55 Filter: ACLFilter{ 56 ResourceTypeFilter: ResourceTypeTopic, 57 ResourceNameFilter: topic, 58 ResourcePatternTypeFilter: PatternTypeLiteral, 59 Operation: ACLOperationTypeRead, 60 PermissionType: ACLPermissionTypeAllow, 61 }, 62 }) 63 if err != nil { 64 t.Fatal(err) 65 } 66 67 expectedDescribeResp := DescribeACLsResponse{ 68 Throttle: 0, 69 Error: makeError(0, ""), 70 Resources: []ACLResource{ 71 { 72 ResourceType: ResourceTypeTopic, 73 ResourceName: topic, 74 PatternType: PatternTypeLiteral, 75 ACLs: []ACLDescription{ 76 { 77 Principal: "User:alice", 78 Host: "*", 79 Operation: ACLOperationTypeRead, 80 PermissionType: ACLPermissionTypeAllow, 81 }, 82 }, 83 }, 84 }, 85 } 86 87 assert.Equal(t, expectedDescribeResp, *describeResp) 88 }