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

     1  package electleaders_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/segmentio/kafka-go/protocol/electleaders"
     7  	"github.com/segmentio/kafka-go/protocol/prototest"
     8  )
     9  
    10  const (
    11  	v0 = 0
    12  	v1 = 1
    13  )
    14  
    15  func TestElectLeadersRequest(t *testing.T) {
    16  	prototest.TestRequest(t, v0, &electleaders.Request{
    17  		TimeoutMs: 500,
    18  		TopicPartitions: []electleaders.RequestTopicPartitions{
    19  			{
    20  				Topic:        "foo",
    21  				PartitionIDs: []int32{100, 101, 102},
    22  			},
    23  		},
    24  	})
    25  
    26  	prototest.TestRequest(t, v1, &electleaders.Request{
    27  		ElectionType: 1,
    28  		TimeoutMs:    500,
    29  		TopicPartitions: []electleaders.RequestTopicPartitions{
    30  			{
    31  				Topic:        "foo",
    32  				PartitionIDs: []int32{100, 101, 102},
    33  			},
    34  		},
    35  	})
    36  }
    37  
    38  func TestElectLeadersResponse(t *testing.T) {
    39  	prototest.TestResponse(t, v0, &electleaders.Response{
    40  		ThrottleTime: 500,
    41  		ReplicaElectionResults: []electleaders.ResponseReplicaElectionResult{
    42  			{
    43  				Topic: "foo",
    44  				PartitionResults: []electleaders.ResponsePartitionResult{
    45  					{PartitionID: 100, ErrorCode: 0, ErrorMessage: ""},
    46  					{PartitionID: 101, ErrorCode: 0, ErrorMessage: ""},
    47  					{PartitionID: 102, ErrorCode: 0, ErrorMessage: ""},
    48  				},
    49  			},
    50  		},
    51  	})
    52  
    53  	prototest.TestResponse(t, v1, &electleaders.Response{
    54  		ThrottleTime: 500,
    55  		ErrorCode:    1,
    56  		ReplicaElectionResults: []electleaders.ResponseReplicaElectionResult{
    57  			{
    58  				Topic: "foo",
    59  				PartitionResults: []electleaders.ResponsePartitionResult{
    60  					{PartitionID: 100, ErrorCode: 0, ErrorMessage: ""},
    61  					{PartitionID: 101, ErrorCode: 0, ErrorMessage: ""},
    62  					{PartitionID: 102, ErrorCode: 0, ErrorMessage: ""},
    63  				},
    64  			},
    65  		},
    66  	})
    67  }