github.com/segmentio/kafka-go@v0.4.48-0.20240318174348-3f6244eb34fd/protocol/addpartitionstotxn/addpartitionstotxn_test.go (about)

     1  package addpartitionstotxn_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/segmentio/kafka-go/protocol/addpartitionstotxn"
     7  	"github.com/segmentio/kafka-go/protocol/prototest"
     8  )
     9  
    10  func TestAddPartitionsToTxnRequest(t *testing.T) {
    11  	for _, version := range []int16{0, 1, 2, 3} {
    12  		prototest.TestRequest(t, version, &addpartitionstotxn.Request{
    13  			TransactionalID: "transaction-id-0",
    14  			ProducerID:      10,
    15  			ProducerEpoch:   100,
    16  			Topics: []addpartitionstotxn.RequestTopic{
    17  				{
    18  					Name:       "topic-1",
    19  					Partitions: []int32{0, 1, 2, 3},
    20  				},
    21  				{
    22  					Name:       "topic-2",
    23  					Partitions: []int32{0, 1, 2},
    24  				},
    25  			},
    26  		})
    27  	}
    28  }
    29  
    30  func TestAddPartitionsToTxnResponse(t *testing.T) {
    31  	for _, version := range []int16{0, 1, 2, 3} {
    32  		prototest.TestResponse(t, version, &addpartitionstotxn.Response{
    33  			ThrottleTimeMs: 20,
    34  			Results: []addpartitionstotxn.ResponseResult{
    35  				{
    36  					Name: "topic-1",
    37  					Results: []addpartitionstotxn.ResponsePartition{
    38  						{
    39  							PartitionIndex: 0,
    40  							ErrorCode:      19,
    41  						},
    42  						{
    43  							PartitionIndex: 1,
    44  							ErrorCode:      0,
    45  						},
    46  					},
    47  				},
    48  				{
    49  					Name: "topic-2",
    50  					Results: []addpartitionstotxn.ResponsePartition{
    51  						{
    52  							PartitionIndex: 0,
    53  							ErrorCode:      0,
    54  						},
    55  					},
    56  				},
    57  			},
    58  		})
    59  	}
    60  }