From 03d1707c76fc8ce96952c3e2f4d5f7e99bde6fc2 Mon Sep 17 00:00:00 2001 From: Nikita Koryabkin Date: Wed, 4 Dec 2019 09:26:45 +0300 Subject: [PATCH] added tests --- sqlmock_go18_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sqlmock_go18_test.go b/sqlmock_go18_test.go index 6080afa..6213266 100644 --- a/sqlmock_go18_test.go +++ b/sqlmock_go18_test.go @@ -642,6 +642,12 @@ func TestPingExpectationsContextTimeout(t *testing.T) { } } +type failArgument struct{} + +func (f failArgument) Match(_ driver.Value) bool { + return false +} + func Test_sqlmock_Exec(t *testing.T) { db, mock, err := New() if err != nil { @@ -652,7 +658,12 @@ func Test_sqlmock_Exec(t *testing.T) { expected := NewResult(1, 1) mock.ExpectExec("SELECT (.+) FROM users WHERE (.+)"). - WillReturnResult(expected) + WillReturnResult(expected). + WithArgs("test") + + mock.ExpectExec("SELECT (.+) FROM animals WHERE (.+)"). + WillReturnError(errors.New("matcher %T could not match %d argument %T - %+v")). + WithArgs(failArgument{}) result, err := mock.(*sqlmock).Exec(query, []driver.Value{"test"}) if err != nil { @@ -663,6 +674,12 @@ func Test_sqlmock_Exec(t *testing.T) { t.Errorf("Results are not equal. Expected: %v, Actual: %v", expected, result) return } + + _, err = mock.(*sqlmock).Exec(query, []driver.Value{failArgument{}}) + if err == nil { + t.Errorf("error expected") + return + } } func Test_sqlmock_Query(t *testing.T) {