mocks.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. Package mocks provides mocks that can be used for testing applications
  3. that use Sarama. The mock types provided by this package implement the
  4. interfaces Sarama exports, so you can use them for dependency injection
  5. in your tests.
  6. All mock instances require you to set expectations on them before you
  7. can use them. It will determine how the mock will behave. If an
  8. expectation is not met, it will make your test fail.
  9. NOTE: this package currently does not fall under the API stability
  10. guarantee of Sarama as it is still considered experimental.
  11. */
  12. package mocks
  13. import (
  14. "errors"
  15. "github.com/Shopify/sarama"
  16. )
  17. // A simple interface that includes the testing.T methods we use to report
  18. // expectation violations when using the mock objects.
  19. type ErrorReporter interface {
  20. Errorf(string, ...interface{})
  21. }
  22. var (
  23. errProduceSuccess error = nil
  24. errOutOfExpectations = errors.New("No more expectations set on mock")
  25. errPartitionConsumerNotStarted = errors.New("The partition consumer was never started")
  26. )
  27. const AnyOffset int64 = -1000
  28. type producerExpectation struct {
  29. Result error
  30. }
  31. type consumerExpectation struct {
  32. Err error
  33. Msg *sarama.ConsumerMessage
  34. }