github.com/QuangHoangHao/kafka-go@v0.4.36/protocol/syncgroup/syncgroup_test.go (about)

     1  package syncgroup_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/QuangHoangHao/kafka-go/protocol/prototest"
     7  	"github.com/QuangHoangHao/kafka-go/protocol/syncgroup"
     8  )
     9  
    10  func TestSyncGroupReq(t *testing.T) {
    11  	for _, version := range []int16{0, 1, 2} {
    12  		prototest.TestRequest(t, version, &syncgroup.Request{
    13  			GroupID:      "group-id-1",
    14  			GenerationID: 10,
    15  			MemberID:     "member-id-1",
    16  			Assignments: []syncgroup.RequestAssignment{
    17  				{
    18  					MemberID:   "member-id-2",
    19  					Assignment: []byte{0, 1, 2, 3, 4},
    20  				},
    21  			},
    22  		})
    23  	}
    24  
    25  	// Version 3 added:
    26  	// GroupInstanceID
    27  	for _, version := range []int16{3, 4} {
    28  		prototest.TestRequest(t, version, &syncgroup.Request{
    29  			GroupID:         "group-id-1",
    30  			GenerationID:    10,
    31  			MemberID:        "member-id-1",
    32  			GroupInstanceID: "group-instance-id",
    33  			Assignments: []syncgroup.RequestAssignment{
    34  				{
    35  					MemberID:   "member-id-2",
    36  					Assignment: []byte{0, 1, 2, 3, 4},
    37  				},
    38  			},
    39  		})
    40  	}
    41  
    42  	// Version 5 added
    43  	// ProtocolType
    44  	// ProtocolName
    45  	for _, version := range []int16{5} {
    46  		prototest.TestRequest(t, version, &syncgroup.Request{
    47  			GroupID:         "group-id-1",
    48  			GenerationID:    10,
    49  			MemberID:        "member-id-1",
    50  			GroupInstanceID: "group-instance-id",
    51  			ProtocolType:    "protocol-type",
    52  			ProtocolName:    "protocol-name",
    53  			Assignments: []syncgroup.RequestAssignment{
    54  				{
    55  					MemberID:   "member-id-2",
    56  					Assignment: []byte{0, 1, 2, 3, 4},
    57  				},
    58  			},
    59  		})
    60  	}
    61  }
    62  
    63  func TestSyncGroupResp(t *testing.T) {
    64  	for _, version := range []int16{0} {
    65  		prototest.TestResponse(t, version, &syncgroup.Response{
    66  			ErrorCode:   10,
    67  			Assignments: []byte{0, 1, 2, 3, 4},
    68  		})
    69  	}
    70  
    71  	// Version 1 added
    72  	// ThrottleTimeMS
    73  	for _, version := range []int16{1, 2, 3, 4} {
    74  		prototest.TestResponse(t, version, &syncgroup.Response{
    75  			ErrorCode:      10,
    76  			ThrottleTimeMS: 1,
    77  			Assignments:    []byte{0, 1, 2, 3, 4},
    78  		})
    79  	}
    80  
    81  	// Version 5 added
    82  	// ProtocolType
    83  	// ProtocolName
    84  	for _, version := range []int16{5} {
    85  		prototest.TestResponse(t, version, &syncgroup.Response{
    86  			ErrorCode:      10,
    87  			ThrottleTimeMS: 1,
    88  			ProtocolType:   "protocol-type",
    89  			ProtocolName:   "protocol-name",
    90  			Assignments:    []byte{0, 1, 2, 3, 4},
    91  		})
    92  	}
    93  }