mocks.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. )
  16. // ErrorReporter is a simple interface that includes the testing.T methods we use to report
  17. // expectation violations when using the mock objects.
  18. type ErrorReporter interface {
  19. Errorf(string, ...interface{})
  20. }
  21. // ValueChecker is a function type to be set in each expectation of the producer mocks
  22. // to check the value passed.
  23. type ValueChecker func(val []byte) error
  24. var (
  25. errProduceSuccess error = nil
  26. errOutOfExpectations = errors.New("No more expectations set on mock")
  27. errPartitionConsumerNotStarted = errors.New("The partition consumer was never started")
  28. )
  29. const AnyOffset int64 = -1000
  30. type producerExpectation struct {
  31. Result error
  32. CheckFunction ValueChecker
  33. }