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

Function TestSyncProducerWithTooFewExpectations

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

Source from the content-addressed store, hash-verified

177}
178
179func TestSyncProducerWithTooFewExpectations(t *testing.T) {
180 trm := newTestReporterMock()
181
182 sp := NewSyncProducer(trm, nil).ExpectSendMessageAndSucceed()
183
184 msg := &sarama.ProducerMessage{Topic: "test", Value: sarama.StringEncoder("test")}
185 if _, _, err := sp.SendMessage(msg); err != nil {
186 t.Error("No error expected on first SendMessage call", err)
187 }
188 if _, _, err := sp.SendMessage(msg); !errors.Is(err, errOutOfExpectations) {
189 t.Error("errOutOfExpectations expected on second SendMessage call, found:", err)
190 }
191
192 if err := sp.Close(); err != nil {
193 t.Error(err)
194 }
195
196 if len(trm.errors) != 1 {
197 t.Error("Expected to report an error")
198 }
199}
200
201func TestSyncProducerWithCheckerFunction(t *testing.T) {
202 trm := newTestReporterMock()

Callers

nothing calls this directly

Calls 8

StringEncoderTypeAlias · 0.92
newTestReporterMockFunction · 0.85
IsMethod · 0.80
NewSyncProducerFunction · 0.70
SendMessageMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected