Skip to content

Commit

Permalink
Move a method used only in tests into the test file
Browse files Browse the repository at this point in the history
  • Loading branch information
eapache committed Jul 6, 2016
1 parent 12de47f commit 1baff7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
15 changes: 15 additions & 0 deletions mocks/async_producer_test.go
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
16 changes: 0 additions & 16 deletions mocks/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ package mocks

import (
"errors"
"fmt"
"regexp"

"github.com/Shopify/sarama"
)
Expand All @@ -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")
Expand Down

0 comments on commit 1baff7c

Please sign in to comment.