ソースを参照

Move expectation types to shared file.

Willem van Bergen 10 年 前
コミット
70471d7073
3 ファイル変更23 行追加19 行削除
  1. 20 0
      mocks/expectations.go
  2. 1 17
      mocks/producer.go
  3. 2 2
      mocks/sync_producer.go

+ 20 - 0
mocks/expectations.go

@@ -0,0 +1,20 @@
+package mocks
+
+import (
+	"errors"
+)
+
+// A simple interafce that includes the testing.T methods we use to report
+// expectation violations when using the mock objects.
+type ExpectationViolationReporter interface {
+	Errorf(string, ...interface{})
+}
+
+var (
+	errProduceSuccess    error = nil
+	errOutOfExpectations       = errors.New("No more expectations set on mock producer")
+)
+
+type producerExpectation struct {
+	Result error
+}

+ 1 - 17
mocks/producer.go

@@ -1,27 +1,11 @@
 package mocks
 
 import (
-	"errors"
 	"sync"
 
 	"github.com/Shopify/sarama"
 )
 
-// A simple interafce that includes the testing.T methods we use to report
-// expectation violations when using the mock objects.
-type TestReporter interface {
-	Errorf(string, ...interface{})
-}
-
-var (
-	errProduceSuccess    error = nil
-	errOutOfExpectations       = errors.New("No more expectations set on mock producer")
-)
-
-type producerExpectation struct {
-	Result error
-}
-
 // Producer implements sarama's Producer interface for testing purposes.
 // Before you can send messages to it's Input channel, you have to set expectations
 // so it knows how to handle the input. This way you can easily test success and
@@ -39,7 +23,7 @@ type Producer struct {
 // be the *testing.T instance of your test method. An error will be written to it if
 // an expectation is violated. The config argument is used to determine whether it
 // should ack successes on the Successes channel.
-func NewProducer(t TestReporter, config *sarama.Config) *Producer {
+func NewProducer(t ExpectationViolationReporter, config *sarama.Config) *Producer {
 	if config == nil {
 		config = sarama.NewConfig()
 	}

+ 2 - 2
mocks/sync_producer.go

@@ -11,7 +11,7 @@ import (
 // and failure scenarios.
 type SyncProducer struct {
 	l            sync.Mutex
-	t            TestReporter
+	t            ExpectationViolationReporter
 	expectations []*producerExpectation
 	lastOffset   int64
 }
@@ -20,7 +20,7 @@ type SyncProducer struct {
 // be the *testing.T instance of your test method. An error will be written to it if
 // an expectation is violated. The config argument is currently unused, but is
 // maintained to be compatible with the async Producer.
-func NewSyncProducer(t TestReporter, config *sarama.Config) *SyncProducer {
+func NewSyncProducer(t ExpectationViolationReporter, config *sarama.Config) *SyncProducer {
 	return &SyncProducer{
 		t:            t,
 		expectations: make([]*producerExpectation, 0),