NewSyncProducer instantiates a new SyncProducer mock. The t argument should be the *testing.T instance of your test method. An error will be written to it if an expectation is violated. The config argument is validated and used to handle partitioning.
(t ErrorReporter, config *sarama.Config)
| 31 | // an expectation is violated. The config argument is validated and used to handle |
| 32 | // partitioning. |
| 33 | func NewSyncProducer(t ErrorReporter, config *sarama.Config) *SyncProducer { |
| 34 | if config == nil { |
| 35 | config = sarama.NewConfig() |
| 36 | } |
| 37 | if err := config.Validate(); err != nil { |
| 38 | t.Errorf("Invalid mock configuration provided: %s", err.Error()) |
| 39 | } |
| 40 | return &SyncProducer{ |
| 41 | t: t, |
| 42 | expectations: make([]*producerExpectation, 0), |
| 43 | TopicConfig: NewTopicConfig(), |
| 44 | newPartitioner: config.Producer.Partitioner, |
| 45 | partitioners: make(map[string]sarama.Partitioner, 1), |
| 46 | isTransactional: config.Producer.Transaction.ID != "", |
| 47 | txnStatus: sarama.ProducerTxnFlagReady, |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | //////////////////////////////////////////////// |
| 52 | // Implement SyncProducer interface |