github.com/segmentio/kafka-go@v0.4.48-0.20240318174348-3f6244eb34fd/alterclientquotas_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 TestClientAlterClientQuotas(t *testing.T) { 12 // Added in Version 2.6.0 https://issues.apache.org/jira/browse/KAFKA-7740 13 if !ktesting.KafkaIsAtLeast("2.6.0") { 14 return 15 } 16 17 const ( 18 entityType = "client-id" 19 entityName = "my-client-id" 20 key = "producer_byte_rate" 21 value = 500000.0 22 ) 23 24 client, shutdown := newLocalClient() 25 defer shutdown() 26 27 alterResp, err := client.AlterClientQuotas(context.Background(), &AlterClientQuotasRequest{ 28 Entries: []AlterClientQuotaEntry{ 29 { 30 Entities: []AlterClientQuotaEntity{ 31 { 32 EntityType: entityType, 33 EntityName: entityName, 34 }, 35 }, 36 Ops: []AlterClientQuotaOps{ 37 { 38 Key: key, 39 Value: value, 40 Remove: false, 41 }, 42 }, 43 }, 44 }, 45 }) 46 47 if err != nil { 48 t.Fatal(err) 49 } 50 51 expectedAlterResp := AlterClientQuotasResponse{ 52 Throttle: 0, 53 Entries: []AlterClientQuotaResponseQuotas{ 54 { 55 Error: makeError(0, ""), 56 Entities: []AlterClientQuotaEntity{ 57 { 58 EntityName: entityName, 59 EntityType: entityType, 60 }, 61 }, 62 }, 63 }, 64 } 65 66 assert.Equal(t, expectedAlterResp, *alterResp) 67 68 describeResp, err := client.DescribeClientQuotas(context.Background(), &DescribeClientQuotasRequest{ 69 Components: []DescribeClientQuotasRequestComponent{ 70 { 71 EntityType: entityType, 72 MatchType: 0, 73 Match: entityName, 74 }, 75 }, 76 }) 77 78 if err != nil { 79 t.Fatal(err) 80 } 81 82 expectedDescribeResp := DescribeClientQuotasResponse{ 83 Throttle: 0, 84 Error: makeError(0, ""), 85 Entries: []DescribeClientQuotasResponseQuotas{ 86 { 87 Entities: []DescribeClientQuotasEntity{ 88 { 89 EntityType: entityType, 90 EntityName: entityName, 91 }, 92 }, 93 Values: []DescribeClientQuotasValue{ 94 { 95 Key: key, 96 Value: value, 97 }, 98 }, 99 }, 100 }, 101 } 102 103 assert.Equal(t, expectedDescribeResp, *describeResp) 104 }