MCPcopy
hub / github.com/IBM/sarama / TestSyncProducerWithCheckerFunction

Function TestSyncProducerWithCheckerFunction

mocks/sync_producer_test.go:201–224  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

199}
200
201func TestSyncProducerWithCheckerFunction(t *testing.T) {
202 trm := newTestReporterMock()
203
204 sp := NewSyncProducer(trm, nil).
205 ExpectSendMessageWithCheckerFunctionAndSucceed(generateRegexpChecker("^tes")).
206 ExpectSendMessageWithCheckerFunctionAndSucceed(generateRegexpChecker("^tes$"))
207
208 msg := &sarama.ProducerMessage{Topic: "test", Value: sarama.StringEncoder("test")}
209 if _, _, err := sp.SendMessage(msg); err != nil {
210 t.Error("No error expected on first SendMessage call, found: ", err)
211 }
212 msg = &sarama.ProducerMessage{Topic: "test", Value: sarama.StringEncoder("test")}
213 if _, _, err := sp.SendMessage(msg); err == nil || !strings.HasPrefix(err.Error(), "No match") {
214 t.Error("Error during value check expected on second SendMessage call, found:", err)
215 }
216
217 if err := sp.Close(); err != nil {
218 t.Error(err)
219 }
220
221 if len(trm.errors) != 1 {
222 t.Error("Expected to report an error")
223 }
224}
225
226func TestSyncProducerWithCheckerFunctionForSendMessagesWithError(t *testing.T) {
227 trm := newTestReporterMock()

Callers

nothing calls this directly

Calls 8

StringEncoderTypeAlias · 0.92
newTestReporterMockFunction · 0.85
generateRegexpCheckerFunction · 0.85
NewSyncProducerFunction · 0.70
SendMessageMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected