github.com/hoveychen/kafka-go@v0.4.42/incrementalalterconfigs_test.go (about) 1 package kafka 2 3 import ( 4 "context" 5 "reflect" 6 "testing" 7 8 ktesting "github.com/hoveychen/kafka-go/testing" 9 ) 10 11 func TestClientIncrementalAlterConfigs(t *testing.T) { 12 if !ktesting.KafkaIsAtLeast("2.4.0") { 13 return 14 } 15 16 const ( 17 configKey = "max.message.bytes" 18 configValue = "200000" 19 ) 20 21 ctx := context.Background() 22 client, shutdown := newLocalClient() 23 defer shutdown() 24 25 topic := makeTopic() 26 createTopic(t, topic, 1) 27 defer deleteTopic(t, topic) 28 29 resp, err := client.IncrementalAlterConfigs( 30 ctx, 31 &IncrementalAlterConfigsRequest{ 32 Resources: []IncrementalAlterConfigsRequestResource{ 33 { 34 ResourceName: topic, 35 ResourceType: ResourceTypeTopic, 36 Configs: []IncrementalAlterConfigsRequestConfig{ 37 { 38 Name: configKey, 39 Value: configValue, 40 ConfigOperation: ConfigOperationSet, 41 }, 42 }, 43 }, 44 }, 45 }, 46 ) 47 if err != nil { 48 t.Fatal(err) 49 } 50 51 expRes := []IncrementalAlterConfigsResponseResource{ 52 { 53 ResourceType: ResourceTypeTopic, 54 ResourceName: topic, 55 }, 56 } 57 if !reflect.DeepEqual(expRes, resp.Resources) { 58 t.Error( 59 "Wrong response resources", 60 "expected", expRes, 61 "got", resp.Resources, 62 ) 63 } 64 65 dResp, err := client.DescribeConfigs( 66 ctx, 67 &DescribeConfigsRequest{ 68 Resources: []DescribeConfigRequestResource{ 69 { 70 ResourceType: ResourceTypeTopic, 71 ResourceName: topic, 72 ConfigNames: []string{ 73 "max.message.bytes", 74 }, 75 }, 76 }, 77 }, 78 ) 79 if err != nil { 80 t.Fatal(err) 81 } 82 if len(dResp.Resources) != 1 || len(dResp.Resources[0].ConfigEntries) != 1 { 83 t.Fatal("Invalid structure for DescribeResourcesResponse") 84 } 85 86 v := dResp.Resources[0].ConfigEntries[0].ConfigValue 87 if v != configValue { 88 t.Error( 89 "Wrong altered value for max.message.bytes", 90 "expected", configValue, 91 "got", v, 92 ) 93 } 94 }