Skip to content

Commit

Permalink
allow to construct mock sender for unit testing
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksander Slominski <aslom@us.ibm.com>
  • Loading branch information
aslom committed Jul 31, 2020
1 parent 2d83dc1 commit 6a501d7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions protocol/kafka_sarama/v2/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Sender struct {
syncProducer sarama.SyncProducer
}


// NewSender returns a binding.Sender that sends messages to a specific receiverTopic using sarama.SyncProducer
func NewSender(brokers []string, saramaConfig *sarama.Config, topic string, options ...SenderOptionFunc) (*Sender, error) {
// Force this setting because it's required by sarama SyncProducer
Expand All @@ -36,6 +37,11 @@ func NewSenderFromClient(client sarama.Client, topic string, options ...SenderOp
return makeSender(producer, topic, options...), nil
}

// NewSenderFromSyncProducer returns a binding.Sender that sends messages to a specific topic using sarama.SyncProducer
func NewSenderFromSyncProducer(topic string, syncProducer sarama.SyncProducer, options ...SenderOptionFunc) (*Sender, error) {
return makeSender(syncProducer, topic, options...), nil
}

func makeSender(syncProducer sarama.SyncProducer, topic string, options ...SenderOptionFunc) *Sender {
s := &Sender{
topic: topic,
Expand Down

0 comments on commit 6a501d7

Please sign in to comment.