mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2024-12-10 10:10:05 +02:00
add bool type to query arg matcher
This commit is contained in:
parent
f55ca83ba0
commit
4a802e4278
@ -358,6 +358,10 @@ func (e *queryBasedExpectation) argsMatches(args []driver.Value) bool {
|
|||||||
if vi.String() != ai.String() {
|
if vi.String() != ai.String() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
case reflect.Bool:
|
||||||
|
if vi.Bool() != ai.Bool() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// compare types like time.Time based on type only
|
// compare types like time.Time based on type only
|
||||||
if vi.Kind() != ai.Kind() {
|
if vi.Kind() != ai.Kind() {
|
||||||
|
@ -60,8 +60,37 @@ func TestQueryExpectationArgComparison(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestQueryExpectationArgComparisonBool(t *testing.T) {
|
||||||
|
var e *queryBasedExpectation
|
||||||
|
|
||||||
|
e = &queryBasedExpectation{args: []driver.Value{true}}
|
||||||
|
against := []driver.Value{true}
|
||||||
|
if !e.argsMatches(against) {
|
||||||
|
t.Error("arguments should match, since arguments are the same")
|
||||||
|
}
|
||||||
|
|
||||||
|
e = &queryBasedExpectation{args: []driver.Value{false}}
|
||||||
|
against = []driver.Value{false}
|
||||||
|
if !e.argsMatches(against) {
|
||||||
|
t.Error("arguments should match, since argument are the same")
|
||||||
|
}
|
||||||
|
|
||||||
|
e = &queryBasedExpectation{args: []driver.Value{true}}
|
||||||
|
against = []driver.Value{false}
|
||||||
|
if e.argsMatches(against) {
|
||||||
|
t.Error("arguments should not match, since argument is different")
|
||||||
|
}
|
||||||
|
|
||||||
|
e = &queryBasedExpectation{args: []driver.Value{false}}
|
||||||
|
against = []driver.Value{true}
|
||||||
|
if e.argsMatches(against) {
|
||||||
|
t.Error("arguments should not match, since argument is different")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestQueryExpectationSqlMatch(t *testing.T) {
|
func TestQueryExpectationSqlMatch(t *testing.T) {
|
||||||
e := &ExpectedExec{}
|
e := &ExpectedExec{}
|
||||||
|
|
||||||
e.sqlRegex = regexp.MustCompile("SELECT x FROM")
|
e.sqlRegex = regexp.MustCompile("SELECT x FROM")
|
||||||
if !e.queryMatches("SELECT x FROM someting") {
|
if !e.queryMatches("SELECT x FROM someting") {
|
||||||
t.Errorf("Sql must have matched the query")
|
t.Errorf("Sql must have matched the query")
|
||||||
|
Loading…
Reference in New Issue
Block a user