Skip to content

Commit

Permalink
fix: mock sync producer does not handle the offset while sending mess…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
XSAM committed Jul 10, 2020
1 parent 5933302 commit e6cb2f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mocks/sync_producer.go
Expand Up @@ -97,6 +97,8 @@ func (sp *SyncProducer) SendMessages(msgs []*sarama.ProducerMessage) error {
if expectation.Result != errProduceSuccess {
return expectation.Result
}
sp.lastOffset++
msgs[i].Offset = sp.lastOffset
}
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions mocks/sync_producer_test.go
Expand Up @@ -161,6 +161,12 @@ func TestSyncProducerWithCheckerFunctionForSendMessagesWithoutError(t *testing.T
t.Error("No error expected on SendMessages call, found: ", err)
}

for i, msg := range msgs {
if int64(i+1) != msg.Offset {
t.Errorf("The %dth message should have been assigned offset 1, but got %d", i, msg.Offset)
}
}

if err := sp.Close(); err != nil {
t.Error(err)
}
Expand Down

0 comments on commit e6cb2f9

Please sign in to comment.