Skip to content

Commit 893be7d

Browse files
committed
Permit setting version on mock produce response
This allows setting the version of the message data struct for MockProduceResponse. This change is very similar to what was already done in pull request IBM#939 In order to mock a "produce" request for Kafka version 0.10.2.0 you would use the following: leader.SetHandlerByMap(map[string]MockResponse{ "ProduceRequest": NewMockProduceResponse(t). SetVersion(2). SetError("my_topic", 0, ErrNoError), })
1 parent f196330 commit 893be7d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

async_producer_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ func TestAsyncProducerFlusherRetryCondition(t *testing.T) {
639639

640640
leader.SetHandlerByMap(map[string]MockResponse{
641641
"ProduceRequest": NewMockProduceResponse(t).
642+
SetVersion(0).
642643
SetError("my_topic", 0, ErrNoError),
643644
})
644645

mockresponses.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ func (mr *MockOffsetCommitResponse) getError(group, topic string, partition int3
384384

385385
// MockProduceResponse is a `ProduceResponse` builder.
386386
type MockProduceResponse struct {
387+
version int16
387388
errors map[string]map[int32]KError
388389
t TestReporter
389390
}
@@ -392,6 +393,11 @@ func NewMockProduceResponse(t TestReporter) *MockProduceResponse {
392393
return &MockProduceResponse{t: t}
393394
}
394395

396+
func (mr *MockProduceResponse) SetVersion(version int16) *MockProduceResponse {
397+
mr.version = version
398+
return mr
399+
}
400+
395401
func (mr *MockProduceResponse) SetError(topic string, partition int32, kerror KError) *MockProduceResponse {
396402
if mr.errors == nil {
397403
mr.errors = make(map[string]map[int32]KError)
@@ -407,7 +413,9 @@ func (mr *MockProduceResponse) SetError(topic string, partition int32, kerror KE
407413

408414
func (mr *MockProduceResponse) For(reqBody versionedDecoder) encoder {
409415
req := reqBody.(*ProduceRequest)
410-
res := &ProduceResponse{}
416+
res := &ProduceResponse{
417+
Version: mr.version,
418+
}
411419
for topic, partitions := range req.records {
412420
for partition := range partitions {
413421
res.AddTopicPartition(topic, partition, mr.getError(topic, partition))

0 commit comments

Comments
 (0)