bsm / sarama-cluster

Cluster extensions for Sarama, the Go client library for Apache Kafka 0.9 [DEPRECATED]
MIT License
1.01k stars 222 forks source link

Mocking and Testing #264

Closed jeroenrinzema closed 6 years ago

jeroenrinzema commented 6 years ago

Hi, I am working on a small application that uses sarama-cluster and started to write some tests. Here I started to wonder if it is plausible to to mock sarama cluster without running Kafka. I currently created a small interface of the Consumer struct that allows me to mock a sarama-cluster consumer.

type ClusterConsumer interface {
  Messages() <-chan *sarama.ConsumerMessage
}

But I was wondering if there are other ways plausible. I tried creating a mock broker (sarama.NewMockBroker) but was unsuccessful to create/connect a new consumer.

https://gist.github.com/jeroenrinzema/7ea51136183ba42b81413cc6bb8d7e02

dim commented 6 years ago

Hmm, we are normally just doing what you are doing, i.e. have a common interface. I assume this may become easier in future: https://github.com/Shopify/sarama/pull/1099. I will close this one as sarama-cluster is now semi-deprecated in favour of ^^

jeroenrinzema commented 6 years ago

@dim, thanks i was also following Shopify/sarama#1099 and will try again once that PR is merged.