File: incrementalalterconfigs_test.go

package info (click to toggle)
golang-github-segmentio-kafka-go 0.4.49%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,292 kB
  • sloc: sh: 17; makefile: 10
file content (94 lines) | stat: -rw-r--r-- 1,835 bytes parent folder | download
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
package kafka

import (
	"context"
	"reflect"
	"testing"

	ktesting "github.com/segmentio/kafka-go/testing"
)

func TestClientIncrementalAlterConfigs(t *testing.T) {
	if !ktesting.KafkaIsAtLeast("2.4.0") {
		return
	}

	const (
		configKey   = "max.message.bytes"
		configValue = "200000"
	)

	ctx := context.Background()
	client, shutdown := newLocalClient()
	defer shutdown()

	topic := makeTopic()
	createTopic(t, topic, 1)
	defer deleteTopic(t, topic)

	resp, err := client.IncrementalAlterConfigs(
		ctx,
		&IncrementalAlterConfigsRequest{
			Resources: []IncrementalAlterConfigsRequestResource{
				{
					ResourceName: topic,
					ResourceType: ResourceTypeTopic,
					Configs: []IncrementalAlterConfigsRequestConfig{
						{
							Name:            configKey,
							Value:           configValue,
							ConfigOperation: ConfigOperationSet,
						},
					},
				},
			},
		},
	)
	if err != nil {
		t.Fatal(err)
	}

	expRes := []IncrementalAlterConfigsResponseResource{
		{
			ResourceType: ResourceTypeTopic,
			ResourceName: topic,
		},
	}
	if !reflect.DeepEqual(expRes, resp.Resources) {
		t.Error(
			"Wrong response resources",
			"expected", expRes,
			"got", resp.Resources,
		)
	}

	dResp, err := client.DescribeConfigs(
		ctx,
		&DescribeConfigsRequest{
			Resources: []DescribeConfigRequestResource{
				{
					ResourceType: ResourceTypeTopic,
					ResourceName: topic,
					ConfigNames: []string{
						"max.message.bytes",
					},
				},
			},
		},
	)
	if err != nil {
		t.Fatal(err)
	}
	if len(dResp.Resources) != 1 || len(dResp.Resources[0].ConfigEntries) != 1 {
		t.Fatal("Invalid structure for DescribeResourcesResponse")
	}

	v := dResp.Resources[0].ConfigEntries[0].ConfigValue
	if v != configValue {
		t.Error(
			"Wrong altered value for max.message.bytes",
			"expected", configValue,
			"got", v,
		)
	}
}