github.com/deanMdreon/kafka-go@v0.4.32/createpartitions_test.go (about)

     1  package kafka
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	ktesting "github.com/deanMdreon/kafka-go/testing"
     8  )
     9  
    10  func TestClientCreatePartitions(t *testing.T) {
    11  	if !ktesting.KafkaIsAtLeast("1.0.1") {
    12  		return
    13  	}
    14  
    15  	client, shutdown := newLocalClient()
    16  	defer shutdown()
    17  
    18  	topic := makeTopic()
    19  	createTopic(t, topic, 1)
    20  	defer deleteTopic(t, topic)
    21  
    22  	res, err := client.CreatePartitions(context.Background(), &CreatePartitionsRequest{
    23  		Topics: []TopicPartitionsConfig{
    24  			{
    25  				Name:  topic,
    26  				Count: 2,
    27  				TopicPartitionAssignments: []TopicPartitionAssignment{
    28  					{
    29  						BrokerIDs: []int32{1},
    30  					},
    31  				},
    32  			},
    33  		},
    34  		ValidateOnly: false,
    35  	})
    36  	if err != nil {
    37  		t.Fatal(err)
    38  	}
    39  
    40  	if err := res.Errors[topic]; err != nil {
    41  		t.Error(err)
    42  	}
    43  }
    44  
    45  func TestClientCreatePartitionsNoAssignments(t *testing.T) {
    46  	if !ktesting.KafkaIsAtLeast("1.0.1") {
    47  		return
    48  	}
    49  
    50  	client, shutdown := newLocalClient()
    51  	defer shutdown()
    52  
    53  	topic := makeTopic()
    54  	createTopic(t, topic, 1)
    55  	defer deleteTopic(t, topic)
    56  
    57  	res, err := client.CreatePartitions(context.Background(), &CreatePartitionsRequest{
    58  		Topics: []TopicPartitionsConfig{
    59  			{
    60  				Name:  topic,
    61  				Count: 2,
    62  			},
    63  		},
    64  		ValidateOnly: false,
    65  	})
    66  	if err != nil {
    67  		t.Fatal(err)
    68  	}
    69  
    70  	if err := res.Errors[topic]; err != nil {
    71  		t.Error(err)
    72  	}
    73  }