Skip to content

Commit 2165444

Browse files
committed
add AnyArg func to provide any kind of argument matcher
1 parent de514b7 commit 2165444

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ It only asserts that argument is of `time.Time` type.
188188

189189
## Changes
190190

191-
191+
- **2016-02-23** - added **sqlmock.AnyArg()** function to provide any kind
192+
of argument matcher.
192193
- **2016-02-23** - convert expected arguments to driver.Value as natural
193194
driver does, the change may affect time.Time comparison and will be
194195
stricter. See [issue](https://github.com/DATA-DOG/go-sqlmock/issues/31).

argument.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package sqlmock
2+
3+
import "database/sql/driver"
4+
5+
// Argument interface allows to match
6+
// any argument in specific way when used with
7+
// ExpectedQuery and ExpectedExec expectations.
8+
type Argument interface {
9+
Match(driver.Value) bool
10+
}
11+
12+
// AnyArg will return an Argument which can
13+
// match any kind of arguments.
14+
//
15+
// Useful for time.Time or similar kinds of arguments.
16+
func AnyArg() Argument {
17+
return anyArgument{}
18+
}
19+
20+
type anyArgument struct{}
21+
22+
func (a anyArgument) Match(_ driver.Value) bool {
23+
return true
24+
}

expectations.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import (
88
"sync"
99
)
1010

11-
// Argument interface allows to match
12-
// any argument in specific way when used with
13-
// ExpectedQuery and ExpectedExec expectations.
14-
type Argument interface {
15-
Match(driver.Value) bool
16-
}
17-
1811
// an expectation interface
1912
type expectation interface {
2013
fulfilled() bool

expectations_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import (
88
"time"
99
)
1010

11-
type matcher struct {
12-
}
13-
14-
func (m matcher) Match(driver.Value) bool {
15-
return true
16-
}
17-
1811
func TestQueryExpectationArgComparison(t *testing.T) {
1912
e := &queryBasedExpectation{}
2013
against := []driver.Value{int64(5)}
@@ -53,7 +46,7 @@ func TestQueryExpectationArgComparison(t *testing.T) {
5346
t.Error("arguments should match, but it did not")
5447
}
5548

56-
e.args = []driver.Value{5, matcher{}}
49+
e.args = []driver.Value{5, AnyArg()}
5750
if err := e.argsMatches(against); err != nil {
5851
t.Errorf("arguments should match, but it did not: %s", err)
5952
}

0 commit comments

Comments
 (0)