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

Function TestSyncProducerSendMessagesFaultyEncoder

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

Source from the content-addressed store, hash-verified

324}
325
326func TestSyncProducerSendMessagesFaultyEncoder(t *testing.T) {
327 trm := newTestReporterMock()
328
329 sp := NewSyncProducer(trm, nil).
330 ExpectSendMessageWithCheckerFunctionAndSucceed(generateRegexpChecker("^tes"))
331
332 msg1 := &sarama.ProducerMessage{Topic: "test", Value: faultyEncoder("123")}
333 msgs := []*sarama.ProducerMessage{msg1}
334
335 if err := sp.SendMessages(msgs); err == nil || !strings.Contains(err.Error(), "encode error") {
336 t.Error("Encoding error expected, found: ", err)
337 }
338
339 if err := sp.Close(); err != nil {
340 t.Error(err)
341 }
342
343 if len(trm.errors) != 1 {
344 t.Error("Expected to report 1 errors")
345 }
346}
347
348type faultyEncoder []byte
349

Callers

nothing calls this directly

Calls 8

newTestReporterMockFunction · 0.85
generateRegexpCheckerFunction · 0.85
faultyEncoderTypeAlias · 0.85
NewSyncProducerFunction · 0.70
SendMessagesMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected