Skip to content

Commit

Permalink
Merge pull request #360 from lovoo/tester-improvements
Browse files Browse the repository at this point in the history
tester: implement listing topics and partitions + getoffset
  • Loading branch information
frairon authored Oct 28, 2021
2 parents bfe9747 + f898329 commit 9ff2ce3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions tester/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ func (cm *consumerMock) catchup() int {
}

func (cm *consumerMock) Topics() ([]string, error) {
return nil, fmt.Errorf("Not implemented")
cm.tester.mCodecs.RLock()
defer cm.tester.mCodecs.RUnlock()

var topics []string

for topic := range cm.tester.codecs {
topics = append(topics, topic)
}
return topics, nil
}

func (cm *consumerMock) Partitions(topic string) ([]int32, error) {
return nil, fmt.Errorf("not implemented")
return []int32{0}, nil
}

func (cm *consumerMock) ConsumePartition(topic string, partition int32, offset int64) (sarama.PartitionConsumer, error) {
Expand Down
4 changes: 3 additions & 1 deletion tester/topic_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func (tm *MockTopicManager) GetOffset(topicName string, partitionID int32, time
case sarama.OffsetNewest:
return topic.Hwm(), nil
default:
return 0, fmt.Errorf("only oldest and newest are supported in the mock")
// always return from oldest, because the tester does not store
// timestamps
return 0, nil
}
}

Expand Down

0 comments on commit 9ff2ce3

Please sign in to comment.