diff --git a/README.md b/README.md index b3a074f..a386b44 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,8 @@ It only asserts that argument is of `time.Time` type. ## Changes - +- **2016-02-23** - added **sqlmock.AnyArg()** function to provide any kind + of argument matcher. - **2016-02-23** - convert expected arguments to driver.Value as natural driver does, the change may affect time.Time comparison and will be stricter. See [issue](https://github.com/DATA-DOG/go-sqlmock/issues/31). diff --git a/argument.go b/argument.go new file mode 100644 index 0000000..7727481 --- /dev/null +++ b/argument.go @@ -0,0 +1,24 @@ +package sqlmock + +import "database/sql/driver" + +// Argument interface allows to match +// any argument in specific way when used with +// ExpectedQuery and ExpectedExec expectations. +type Argument interface { + Match(driver.Value) bool +} + +// AnyArg will return an Argument which can +// match any kind of arguments. +// +// Useful for time.Time or similar kinds of arguments. +func AnyArg() Argument { + return anyArgument{} +} + +type anyArgument struct{} + +func (a anyArgument) Match(_ driver.Value) bool { + return true +} diff --git a/expectations.go b/expectations.go index a7c0cec..62b8559 100644 --- a/expectations.go +++ b/expectations.go @@ -8,13 +8,6 @@ import ( "sync" ) -// Argument interface allows to match -// any argument in specific way when used with -// ExpectedQuery and ExpectedExec expectations. -type Argument interface { - Match(driver.Value) bool -} - // an expectation interface type expectation interface { fulfilled() bool diff --git a/expectations_test.go b/expectations_test.go index b36086b..6fd3435 100644 --- a/expectations_test.go +++ b/expectations_test.go @@ -8,13 +8,6 @@ import ( "time" ) -type matcher struct { -} - -func (m matcher) Match(driver.Value) bool { - return true -} - func TestQueryExpectationArgComparison(t *testing.T) { e := &queryBasedExpectation{} against := []driver.Value{int64(5)} @@ -53,7 +46,7 @@ func TestQueryExpectationArgComparison(t *testing.T) { t.Error("arguments should match, but it did not") } - e.args = []driver.Value{5, matcher{}} + e.args = []driver.Value{5, AnyArg()} if err := e.argsMatches(against); err != nil { t.Errorf("arguments should match, but it did not: %s", err) }