(t *testing.T)
| 24 | } |
| 25 | |
| 26 | func TestConsumerHandlesExpectations(t *testing.T) { |
| 27 | consumer := NewConsumer(t, NewTestConfig()) |
| 28 | defer func() { |
| 29 | if err := consumer.Close(); err != nil { |
| 30 | t.Error(err) |
| 31 | } |
| 32 | }() |
| 33 | |
| 34 | consumer.ExpectConsumePartition("test", 0, sarama.OffsetOldest).YieldMessage(&sarama.ConsumerMessage{Value: []byte("hello world")}) |
| 35 | consumer.ExpectConsumePartition("test", 0, sarama.OffsetOldest).YieldError(sarama.ErrOutOfBrokers) |
| 36 | consumer.ExpectConsumePartition("test", 1, sarama.OffsetOldest).YieldMessage(&sarama.ConsumerMessage{Value: []byte("hello world again")}) |
| 37 | consumer.ExpectConsumePartition("other", 0, AnyOffset).YieldMessage(&sarama.ConsumerMessage{Value: []byte("hello other")}) |
| 38 | |
| 39 | pc_test0, err := consumer.ConsumePartition("test", 0, sarama.OffsetOldest) |
| 40 | if err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | test0_msg := <-pc_test0.Messages() |
| 44 | if test0_msg.Topic != "test" || test0_msg.Partition != 0 || string(test0_msg.Value) != "hello world" { |
| 45 | t.Error("Message was not as expected:", test0_msg) |
| 46 | } |
| 47 | test0_err := <-pc_test0.Errors() |
| 48 | if !errors.Is(test0_err, sarama.ErrOutOfBrokers) { |
| 49 | t.Error("Expected sarama.ErrOutOfBrokers, found:", test0_err.Err) |
| 50 | } |
| 51 | |
| 52 | pc_test1, err := consumer.ConsumePartition("test", 1, sarama.OffsetOldest) |
| 53 | if err != nil { |
| 54 | t.Fatal(err) |
| 55 | } |
| 56 | test1_msg := <-pc_test1.Messages() |
| 57 | if test1_msg.Topic != "test" || test1_msg.Partition != 1 || string(test1_msg.Value) != "hello world again" { |
| 58 | t.Error("Message was not as expected:", test1_msg) |
| 59 | } |
| 60 | |
| 61 | pc_other0, err := consumer.ConsumePartition("other", 0, sarama.OffsetNewest) |
| 62 | if err != nil { |
| 63 | t.Fatal(err) |
| 64 | } |
| 65 | other0_msg := <-pc_other0.Messages() |
| 66 | if other0_msg.Topic != "other" || other0_msg.Partition != 0 || string(other0_msg.Value) != "hello other" { |
| 67 | t.Error("Message was not as expected:", other0_msg) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | func TestConsumerHandlesExpectationsPausingResuming(t *testing.T) { |
| 72 | consumer := NewConsumer(t, NewTestConfig()) |
nothing calls this directly
no test coverage detected