github.com/streamdal/segmentio-kafka-go@v0.4.47-streamdal/electleaders_test.go (about)

     1  package kafka
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	ktesting "github.com/segmentio/kafka-go/testing"
     8  )
     9  
    10  func TestClientElectLeaders(t *testing.T) {
    11  	if !ktesting.KafkaIsAtLeast("2.4.0") {
    12  		return
    13  	}
    14  
    15  	ctx := context.Background()
    16  	client, shutdown := newLocalClient()
    17  	defer shutdown()
    18  
    19  	topic := makeTopic()
    20  	createTopic(t, topic, 2)
    21  	defer deleteTopic(t, topic)
    22  
    23  	// Local kafka only has 1 broker, so leader elections are no-ops.
    24  	resp, err := client.ElectLeaders(
    25  		ctx,
    26  		&ElectLeadersRequest{
    27  			Topic:      topic,
    28  			Partitions: []int{0, 1},
    29  		},
    30  	)
    31  
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  	if resp.Error != nil {
    36  		t.Error(
    37  			"Unexpected error in response",
    38  			"expected", nil,
    39  			"got", resp.Error,
    40  		)
    41  	}
    42  	if len(resp.PartitionResults) != 2 {
    43  		t.Error(
    44  			"Unexpected length of partition results",
    45  			"expected", 2,
    46  			"got", len(resp.PartitionResults),
    47  		)
    48  	}
    49  }