1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2024-12-10 10:10:05 +02:00

Merge pull request #28 from mrroman/master

Add bool type to query arg matcher
This commit is contained in:
Gediminas Morkevicius 2016-01-27 18:03:58 +02:00
commit f49a90b6f7
2 changed files with 33 additions and 0 deletions

View File

@ -358,6 +358,10 @@ func (e *queryBasedExpectation) argsMatches(args []driver.Value) bool {
if vi.String() != ai.String() {
return false
}
case reflect.Bool:
if vi.Bool() != ai.Bool() {
return false
}
default:
// compare types like time.Time based on type only
if vi.Kind() != ai.Kind() {

View File

@ -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) {
e := &ExpectedExec{}
e.sqlRegex = regexp.MustCompile("SELECT x FROM")
if !e.queryMatches("SELECT x FROM someting") {
t.Errorf("Sql must have matched the query")