mocks.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // ErrorReporter is 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. // ValueChecker is a function type to be set in each expectation of the producer mocks
  23. // to check the value passed.
  24. type ValueChecker func(val []byte) error
  25. var (
  26. errProduceSuccess error = nil
  27. errOutOfExpectations = errors.New("No more expectations set on mock")
  28. errPartitionConsumerNotStarted = errors.New("The partition consumer was never started")
  29. )
  30. const AnyOffset int64 = -1000
  31. type producerExpectation struct {
  32. Result error
  33. CheckFunction ValueChecker
  34. }
  35. type consumerExpectation struct {
  36. Err error
  37. Msg *sarama.ConsumerMessage
  38. }