@@ -1518,77 +1518,65 @@ func TestParseProduceResponseRoundTrip(t *testing.T) {
15181518}
15191519
15201520func TestEncodeProduceRequestRoundTrip (t * testing.T ) {
1521- header := & RequestHeader {
1522- APIKey : APIKeyProduce ,
1523- APIVersion : 9 ,
1524- CorrelationID : 77 ,
1525- ClientID : strPtr ("test-client" ),
1526- }
15271521 req := & ProduceRequest {
15281522 Acks : - 1 ,
15291523 TimeoutMs : 5000 ,
15301524 Topics : []ProduceTopic {
15311525 {
15321526 Name : "orders" ,
15331527 Partitions : []ProducePartition {
1534- {Partition : 0 , Records : []byte {1 , 2 , 3 , 4 }},
1535- {Partition : 1 , Records : []byte {5 , 6 }},
1528+ {Partition : 0 , Records : []byte {1 , 2 , 3 }},
1529+ {Partition : 1 , Records : []byte {4 , 5 }},
1530+ {Partition : 2 , Records : []byte {6 , 7 , 8 , 9 }},
15361531 },
15371532 },
15381533 {
15391534 Name : "events" ,
15401535 Partitions : []ProducePartition {
1541- {Partition : 0 , Records : []byte {7 , 8 , 9 }},
1536+ {Partition : 0 , Records : []byte {10 }},
1537+ {Partition : 3 , Records : []byte {11 , 12 }},
15421538 },
15431539 },
15441540 },
15451541 }
15461542 for _ , version := range []int16 {3 , 5 , 7 , 8 , 9 , 10 } {
15471543 t .Run (fmt .Sprintf ("v%d" , version ), func (t * testing.T ) {
1548- h := & RequestHeader {
1544+ header := & RequestHeader {
15491545 APIKey : APIKeyProduce ,
15501546 APIVersion : version ,
1551- CorrelationID : header . CorrelationID ,
1552- ClientID : header . ClientID ,
1547+ CorrelationID : 77 ,
1548+ ClientID : strPtr ( "test-client" ) ,
15531549 }
1554- encoded , err := EncodeProduceRequest (h , req , version )
1550+ encoded , err := EncodeProduceRequest (header , req , version )
15551551 if err != nil {
15561552 t .Fatalf ("encode: %v" , err )
15571553 }
1558- parsedHeader , parsedReq , err := ParseRequest (encoded )
1554+ _ , parsedReq , err := ParseRequest (encoded )
15591555 if err != nil {
15601556 t .Fatalf ("parse: %v" , err )
15611557 }
1562- if parsedHeader .CorrelationID != h .CorrelationID {
1563- t .Fatalf ("correlation id: got %d want %d" , parsedHeader .CorrelationID , h .CorrelationID )
1564- }
1565- produceReq , ok := parsedReq .(* ProduceRequest )
1558+ got , ok := parsedReq .(* ProduceRequest )
15661559 if ! ok {
15671560 t .Fatalf ("expected *ProduceRequest, got %T" , parsedReq )
15681561 }
1569- if produceReq . Acks != req .Acks {
1570- t .Fatalf ("acks : got %d want %d" , produceReq . Acks , req .Acks )
1562+ if len ( got . Topics ) != len ( req .Topics ) {
1563+ t .Fatalf ("topic count : got %d want %d" , len ( got . Topics ), len ( req .Topics ) )
15711564 }
1572- if produceReq .TimeoutMs != req .TimeoutMs {
1573- t .Fatalf ("timeout: got %d want %d" , produceReq .TimeoutMs , req .TimeoutMs )
1574- }
1575- if len (produceReq .Topics ) != len (req .Topics ) {
1576- t .Fatalf ("topic count: got %d want %d" , len (produceReq .Topics ), len (req .Topics ))
1577- }
1578- for ti , topic := range produceReq .Topics {
1579- if topic .Name != req .Topics [ti ].Name {
1580- t .Fatalf ("topic[%d] name: got %q want %q" , ti , topic .Name , req .Topics [ti ].Name )
1565+ for ti , topic := range got .Topics {
1566+ want := req .Topics [ti ]
1567+ if topic .Name != want .Name {
1568+ t .Fatalf ("topic[%d] name: got %q want %q" , ti , topic .Name , want .Name )
15811569 }
1582- if len (topic .Partitions ) != len (req . Topics [ ti ] .Partitions ) {
1583- t .Fatalf ("topic[%d] partition count: got %d want %d" , ti , len (topic .Partitions ), len (req . Topics [ ti ] .Partitions ))
1570+ if len (topic .Partitions ) != len (want .Partitions ) {
1571+ t .Fatalf ("topic[%d] partition count: got %d want %d" , ti , len (topic .Partitions ), len (want .Partitions ))
15841572 }
15851573 for pi , part := range topic .Partitions {
1586- want := req . Topics [ ti ] .Partitions [pi ]
1587- if part .Partition != want .Partition {
1588- t .Fatalf ("topic[%d].part[%d] index: got %d want %d" , ti , pi , part .Partition , want .Partition )
1574+ wantPart := want .Partitions [pi ]
1575+ if part .Partition != wantPart .Partition {
1576+ t .Fatalf ("topic[%d].part[%d] index: got %d want %d" , ti , pi , part .Partition , wantPart .Partition )
15891577 }
1590- if string (part .Records ) != string (want .Records ) {
1591- t .Fatalf ("topic[%d].part[%d] records: got %v want %v " , ti , pi , part .Records , want .Records )
1578+ if string (part .Records ) != string (wantPart .Records ) {
1579+ t .Fatalf ("topic[%d].part[%d] records: got %x want %x " , ti , pi , part .Records , wantPart .Records )
15921580 }
15931581 }
15941582 }
0 commit comments