1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2025-06-25 00:26:45 +02:00

add custom argument matching

This commit is contained in:
Algirdas Matas
2014-05-29 16:43:37 +03:00
parent fa31f407df
commit 27fabfa23a
3 changed files with 196 additions and 171 deletions

View File

@ -6,6 +6,12 @@ import (
"regexp"
)
// Argument interface allows to match
// any argument in specific way
type Argument interface {
Match(driver.Value) bool
}
// an expectation interface
type expectation interface {
fulfilled() bool
@ -47,6 +53,13 @@ func (e *queryBasedExpectation) argsMatches(args []driver.Value) bool {
return false
}
for k, v := range args {
matcher, ok := e.args[k].(Argument)
if ok {
if !matcher.Match(v) {
return false
}
continue
}
vi := reflect.ValueOf(v)
ai := reflect.ValueOf(e.args[k])
switch vi.Kind() {

View File

@ -6,6 +6,13 @@ import (
"time"
)
type matcher struct {
}
func (m matcher) Match(driver.Value) bool {
return true
}
func TestQueryExpectationArgComparison(t *testing.T) {
e := &queryBasedExpectation{}
against := []driver.Value{5}
@ -44,4 +51,9 @@ func TestQueryExpectationArgComparison(t *testing.T) {
if !e.argsMatches(against) {
t.Error("arguments should match (time will be compared only by type), but it did not")
}
against = []driver.Value{5, matcher{}}
if !e.argsMatches(against) {
t.Error("arguments should match, but it did not")
}
}