MCPcopy
hub / github.com/segmentio/kafka-go / TestClientMetadata

Function TestClientMetadata

metadata_test.go:8–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestClientMetadata(t *testing.T) {
9 client, topic, shutdown := newLocalClientAndTopic()
10 defer shutdown()
11
12 metadata, err := client.Metadata(context.Background(), &MetadataRequest{
13 Topics: []string{topic},
14 })
15
16 if err != nil {
17 t.Fatal(err)
18 }
19
20 if len(metadata.Brokers) == 0 {
21 t.Error("no brokers were returned in the metadata response")
22 }
23
24 for _, b := range metadata.Brokers {
25 if b == (Broker{}) {
26 t.Error("unexpected broker with zero-value in metadata response")
27 }
28 }
29
30 if len(metadata.Topics) == 0 {
31 t.Error("no topics were returned in the metadata response")
32 } else {
33 topicMetadata := metadata.Topics[0]
34
35 if topicMetadata.Name != topic {
36 t.Error("invalid topic name:", topicMetadata.Name)
37 }
38
39 if len(topicMetadata.Partitions) == 0 {
40 t.Error("no partitions were returned in the topic metadata response")
41 } else {
42 partitionMetadata := topicMetadata.Partitions[0]
43
44 if partitionMetadata.Topic != topic {
45 t.Error("invalid partition topic name:", partitionMetadata.Topic)
46 }
47
48 if partitionMetadata.ID != 0 {
49 t.Error("invalid partition index:", partitionMetadata.ID)
50 }
51
52 if partitionMetadata.Leader == (Broker{}) {
53 t.Error("no partition leader was returned in the partition metadata response")
54 }
55
56 if partitionMetadata.Error != nil {
57 t.Error("unexpected error found in the partition metadata response:", partitionMetadata.Error)
58 }
59
60 // assume newLocalClientAndTopic creates the topic with one
61 // partition
62 if len(topicMetadata.Partitions) > 1 {
63 t.Error("too many partitions were returned in the topic metadata response")
64 }
65 }

Callers

nothing calls this directly

Calls 3

MetadataMethod · 0.80
newLocalClientAndTopicFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected