github.com/hoveychen/kafka-go@v0.4.42/alterpartitionreassignments_test.go (about)

     1  package kafka
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	ktesting "github.com/hoveychen/kafka-go/testing"
     8  )
     9  
    10  func TestClientAlterPartitionReassignments(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 any partition reassignments are really no-ops.
    24  	resp, err := client.AlterPartitionReassignments(
    25  		ctx,
    26  		&AlterPartitionReassignmentsRequest{
    27  			Topic: topic,
    28  			Assignments: []AlterPartitionReassignmentsRequestAssignment{
    29  				{
    30  					PartitionID: 0,
    31  					BrokerIDs:   []int{1},
    32  				},
    33  				{
    34  					PartitionID: 1,
    35  					BrokerIDs:   []int{1},
    36  				},
    37  			},
    38  		},
    39  	)
    40  
    41  	if err != nil {
    42  		t.Fatal(err)
    43  	}
    44  	if resp.Error != nil {
    45  		t.Error(
    46  			"Unexpected error in response",
    47  			"expected", nil,
    48  			"got", resp.Error,
    49  		)
    50  	}
    51  	if len(resp.PartitionResults) != 2 {
    52  		t.Error(
    53  			"Unexpected length of partition results",
    54  			"expected", 2,
    55  			"got", len(resp.PartitionResults),
    56  		)
    57  	}
    58  }