github.com/QuangHoangHao/kafka-go@v0.4.36/describeconfigs_test.go (about) 1 package kafka 2 3 import ( 4 "context" 5 "testing" 6 7 ktesting "github.com/QuangHoangHao/kafka-go/testing" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestClientDescribeConfigs(t *testing.T) { 12 if !ktesting.KafkaIsAtLeast("0.11.0") { 13 return 14 } 15 16 const ( 17 MaxMessageBytes = "max.message.bytes" 18 MaxMessageBytesValue = "200000" 19 ) 20 21 client, shutdown := newLocalClient() 22 defer shutdown() 23 24 topic := makeTopic() 25 createTopic(t, topic, 1) 26 defer deleteTopic(t, topic) 27 28 _, err := client.AlterConfigs(context.Background(), &AlterConfigsRequest{ 29 Resources: []AlterConfigRequestResource{{ 30 ResourceType: ResourceTypeTopic, 31 ResourceName: topic, 32 Configs: []AlterConfigRequestConfig{{ 33 Name: MaxMessageBytes, 34 Value: MaxMessageBytesValue, 35 }, 36 }, 37 }}, 38 }) 39 40 if err != nil { 41 t.Fatal(err) 42 } 43 44 describeResp, err := client.DescribeConfigs(context.Background(), &DescribeConfigsRequest{ 45 Resources: []DescribeConfigRequestResource{{ 46 ResourceType: ResourceTypeTopic, 47 ResourceName: topic, 48 ConfigNames: []string{MaxMessageBytes}, 49 }}, 50 }) 51 52 if err != nil { 53 t.Fatal(err) 54 } 55 56 maxMessageBytesValue := "0" 57 for _, resource := range describeResp.Resources { 58 if resource.ResourceType == int8(ResourceTypeTopic) && resource.ResourceName == topic { 59 for _, entry := range resource.ConfigEntries { 60 if entry.ConfigName == MaxMessageBytes { 61 maxMessageBytesValue = entry.ConfigValue 62 } 63 } 64 } 65 } 66 assert.Equal(t, maxMessageBytesValue, MaxMessageBytesValue) 67 }