From 4a802e4278813cd2f0fed7b28edade61359f7b53 Mon Sep 17 00:00:00 2001 From: Konrad Mrozek Date: Tue, 26 Jan 2016 15:19:23 +0100 Subject: [PATCH] add bool type to query arg matcher --- expectations.go | 4 ++++ expectations_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/expectations.go b/expectations.go index 36076e6..63e6dc3 100644 --- a/expectations.go +++ b/expectations.go @@ -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() { diff --git a/expectations_test.go b/expectations_test.go index caa91dd..d973c68 100644 --- a/expectations_test.go +++ b/expectations_test.go @@ -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")