github.com/segmentio/kafka-go@v0.4.48-0.20240318174348-3f6244eb34fd/protocol/listoffsets/listoffsets_test.go (about) 1 package listoffsets_test 2 3 import ( 4 "testing" 5 6 "github.com/segmentio/kafka-go/protocol/listoffsets" 7 "github.com/segmentio/kafka-go/protocol/prototest" 8 ) 9 10 const ( 11 v1 = 1 12 v4 = 4 13 ) 14 15 func TestListOffsetsRequest(t *testing.T) { 16 prototest.TestRequest(t, v1, &listoffsets.Request{ 17 ReplicaID: 1, 18 Topics: []listoffsets.RequestTopic{ 19 { 20 Topic: "topic-1", 21 Partitions: []listoffsets.RequestPartition{ 22 {Partition: 0, Timestamp: 1e9}, 23 {Partition: 1, Timestamp: 1e9}, 24 {Partition: 2, Timestamp: 1e9}, 25 }, 26 }, 27 }, 28 }) 29 30 prototest.TestRequest(t, v4, &listoffsets.Request{ 31 ReplicaID: 1, 32 IsolationLevel: 2, 33 Topics: []listoffsets.RequestTopic{ 34 { 35 Topic: "topic-1", 36 Partitions: []listoffsets.RequestPartition{ 37 {Partition: 0, Timestamp: 1e9}, 38 {Partition: 1, Timestamp: 1e9}, 39 {Partition: 2, Timestamp: 1e9}, 40 }, 41 }, 42 { 43 Topic: "topic-2", 44 Partitions: []listoffsets.RequestPartition{ 45 {Partition: 0, CurrentLeaderEpoch: 10, Timestamp: 1e9}, 46 {Partition: 1, CurrentLeaderEpoch: 11, Timestamp: 1e9}, 47 {Partition: 2, CurrentLeaderEpoch: 12, Timestamp: 1e9}, 48 }, 49 }, 50 }, 51 }) 52 } 53 54 func TestListOffsetsResponse(t *testing.T) { 55 prototest.TestResponse(t, v1, &listoffsets.Response{ 56 Topics: []listoffsets.ResponseTopic{ 57 { 58 Topic: "topic-1", 59 Partitions: []listoffsets.ResponsePartition{ 60 { 61 Partition: 0, 62 ErrorCode: 0, 63 Timestamp: 1e9, 64 Offset: 1234567890, 65 }, 66 }, 67 }, 68 }, 69 }) 70 71 prototest.TestResponse(t, v4, &listoffsets.Response{ 72 ThrottleTimeMs: 1234, 73 Topics: []listoffsets.ResponseTopic{ 74 { 75 Topic: "topic-1", 76 Partitions: []listoffsets.ResponsePartition{ 77 { 78 Partition: 0, 79 ErrorCode: 0, 80 Timestamp: 1e9, 81 Offset: 1234567890, 82 LeaderEpoch: 10, 83 }, 84 }, 85 }, 86 { 87 Topic: "topic-2", 88 Partitions: []listoffsets.ResponsePartition{ 89 { 90 Partition: 0, 91 ErrorCode: 0, 92 Timestamp: 1e9, 93 Offset: 1234567890, 94 LeaderEpoch: 10, 95 }, 96 { 97 Partition: 1, 98 ErrorCode: 2, 99 }, 100 }, 101 }, 102 }, 103 }) 104 }