From 1baff7ce02f768e4b13248fb7aaa0c4788fbcec8 Mon Sep 17 00:00:00 2001 From: Evan Huus Date: Wed, 6 Jul 2016 12:01:45 -0400 Subject: [PATCH] Move a method used only in tests into the test file --- mocks/async_producer_test.go | 15 +++++++++++++++ mocks/mocks.go | 16 ---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/mocks/async_producer_test.go b/mocks/async_producer_test.go index e373142e6..b5d92aad8 100644 --- a/mocks/async_producer_test.go +++ b/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 } diff --git a/mocks/mocks.go b/mocks/mocks.go index 60955a3e0..4adb838d9 100644 --- a/mocks/mocks.go +++ b/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")