mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2025-04-21 11:56:50 +02:00
add AnyArg func to provide any kind of argument matcher
This commit is contained in:
parent
de514b7bf0
commit
2165444c8d
@ -188,7 +188,8 @@ It only asserts that argument is of `time.Time` type.
|
|||||||
|
|
||||||
## Changes
|
## 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
|
- **2016-02-23** - convert expected arguments to driver.Value as natural
|
||||||
driver does, the change may affect time.Time comparison and will be
|
driver does, the change may affect time.Time comparison and will be
|
||||||
stricter. See [issue](https://github.com/DATA-DOG/go-sqlmock/issues/31).
|
stricter. See [issue](https://github.com/DATA-DOG/go-sqlmock/issues/31).
|
||||||
|
24
argument.go
Normal file
24
argument.go
Normal file
@ -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
|
||||||
|
}
|
@ -8,13 +8,6 @@ import (
|
|||||||
"sync"
|
"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
|
// an expectation interface
|
||||||
type expectation interface {
|
type expectation interface {
|
||||||
fulfilled() bool
|
fulfilled() bool
|
||||||
|
@ -8,13 +8,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type matcher struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m matcher) Match(driver.Value) bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestQueryExpectationArgComparison(t *testing.T) {
|
func TestQueryExpectationArgComparison(t *testing.T) {
|
||||||
e := &queryBasedExpectation{}
|
e := &queryBasedExpectation{}
|
||||||
against := []driver.Value{int64(5)}
|
against := []driver.Value{int64(5)}
|
||||||
@ -53,7 +46,7 @@ func TestQueryExpectationArgComparison(t *testing.T) {
|
|||||||
t.Error("arguments should match, but it did not")
|
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 {
|
if err := e.argsMatches(against); err != nil {
|
||||||
t.Errorf("arguments should match, but it did not: %s", err)
|
t.Errorf("arguments should match, but it did not: %s", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user