Browse Source

Move a method used only in tests into the test file

Evan Huus 9 năm trước cách đây
mục cha
commit
1baff7ce02
2 tập tin đã thay đổi với 15 bổ sung16 xóa
  1. 15 0
      mocks/async_producer_test.go
  2. 0 16
      mocks/mocks.go

+ 15 - 0
mocks/async_producer_test.go

@@ -1,13 +1,28 @@
 package mocks
 
 import (
+	"errors"
 	"fmt"
+	"regexp"
 	"strings"
 	"testing"
 
 	"github.com/Shopify/sarama"
 )
 
+func generateRegexpChecker(re string) func([]byte) error {
+	return func(val []byte) error {
+		matched, err := regexp.MatchString(re, string(val))
+		if err != nil {
+			return errors.New("Error while trying to match the input message with the expected pattern: " + err.Error())
+		}
+		if !matched {
+			return fmt.Errorf("No match between input value \"%s\" and expected pattern \"%s\"", val, re)
+		}
+		return nil
+	}
+}
+
 type testReporterMock struct {
 	errors []string
 }

+ 0 - 16
mocks/mocks.go

@@ -15,8 +15,6 @@ package mocks
 
 import (
 	"errors"
-	"fmt"
-	"regexp"
 
 	"github.com/Shopify/sarama"
 )
@@ -31,20 +29,6 @@ type ErrorReporter interface {
 // to check the value passed.
 type ValueChecker func(val []byte) error
 
-// This function is used inside the mocks unit tests to generate ValueCheckers
-func generateRegexpChecker(re string) func([]byte) error {
-	return func(val []byte) error {
-		matched, err := regexp.MatchString(re, string(val))
-		if err != nil {
-			return errors.New("Error while trying to match the input message with the expected pattern: " + err.Error())
-		}
-		if !matched {
-			return fmt.Errorf("No match between input value \"%s\" and expected pattern \"%s\"", val, re)
-		}
-		return nil
-	}
-}
-
 var (
 	errProduceSuccess              error = nil
 	errOutOfExpectations                 = errors.New("No more expectations set on mock")