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

Function TestConsumerTopicMetadata

mocks/consumer_test.go:281–322  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

279}
280
281func TestConsumerTopicMetadata(t *testing.T) {
282 trm := newTestReporterMock()
283 consumer := NewConsumer(trm, NewTestConfig())
284
285 consumer.SetTopicMetadata(map[string][]int32{
286 "test1": {0, 1, 2, 3},
287 "test2": {0, 1, 2, 3, 4, 5, 6, 7},
288 })
289
290 topics, err := consumer.Topics()
291 if err != nil {
292 t.Error(t)
293 }
294
295 sortedTopics := sort.StringSlice(topics)
296 sortedTopics.Sort()
297 if len(sortedTopics) != 2 || sortedTopics[0] != "test1" || sortedTopics[1] != "test2" {
298 t.Error("Unexpected topics returned:", sortedTopics)
299 }
300
301 partitions1, err := consumer.Partitions("test1")
302 if err != nil {
303 t.Error(t)
304 }
305
306 if len(partitions1) != 4 {
307 t.Error("Unexpected partitions returned:", len(partitions1))
308 }
309
310 partitions2, err := consumer.Partitions("test2")
311 if err != nil {
312 t.Error(t)
313 }
314
315 if len(partitions2) != 8 {
316 t.Error("Unexpected partitions returned:", len(partitions2))
317 }
318
319 if len(trm.errors) != 0 {
320 t.Errorf("Expected no expectation failures to be set on the error reporter.")
321 }
322}
323
324func TestConsumerUnexpectedTopicMetadata(t *testing.T) {
325 trm := newTestReporterMock()

Callers

nothing calls this directly

Calls 8

SetTopicMetadataMethod · 0.95
TopicsMethod · 0.95
PartitionsMethod · 0.95
newTestReporterMockFunction · 0.85
NewConsumerFunction · 0.70
NewTestConfigFunction · 0.70
ErrorMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected