From 7c9a431ac4e5774d5a103983c16d56626b911a3d Mon Sep 17 00:00:00 2001 From: Ivo Gosemann Date: Mon, 1 Aug 2022 11:07:26 +0200 Subject: [PATCH] Adds fix to before go 1.8 --- expectations_before_go18.go | 3 +++ expectations_before_go18_test.go | 4 ++-- expectations_go18_test.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/expectations_before_go18.go b/expectations_before_go18.go index f6e7b4e..0831863 100644 --- a/expectations_before_go18.go +++ b/expectations_before_go18.go @@ -17,6 +17,9 @@ func (e *ExpectedQuery) WillReturnRows(rows *Rows) *ExpectedQuery { func (e *queryBasedExpectation) argsMatches(args []namedValue) error { if nil == e.args { + if len(args) > 0 { + return fmt.Errorf("expected 0, but got %d arguments", len(args)) + } return nil } if len(args) != len(e.args) { diff --git a/expectations_before_go18_test.go b/expectations_before_go18_test.go index 897ebff..81dc8cf 100644 --- a/expectations_before_go18_test.go +++ b/expectations_before_go18_test.go @@ -11,8 +11,8 @@ import ( func TestQueryExpectationArgComparison(t *testing.T) { e := &queryBasedExpectation{converter: driver.DefaultParameterConverter} against := []namedValue{{Value: int64(5), Ordinal: 1}} - if err := e.argsMatches(against); err != nil { - t.Errorf("arguments should match, since the no expectation was set, but got err: %s", err) + if err := e.argsMatches(against); err == nil { + t.Error("arguments should not match, since no expectation was set, but argument was passed") } e.args = []driver.Value{5, "str"} diff --git a/expectations_go18_test.go b/expectations_go18_test.go index 3e8821c..d5638bc 100644 --- a/expectations_go18_test.go +++ b/expectations_go18_test.go @@ -13,7 +13,7 @@ func TestQueryExpectationArgComparison(t *testing.T) { e := &queryBasedExpectation{converter: driver.DefaultParameterConverter} against := []driver.NamedValue{{Value: int64(5), Ordinal: 1}} if err := e.argsMatches(against); err == nil { - t.Errorf("arguments should not match, since no expectation was set, but argument was passed") + t.Error("arguments should not match, since no expectation was set, but argument was passed") } e.args = []driver.Value{5, "str"}