Skip to content

Commit 03d1707

Browse files
author
Nikita Koryabkin
committed
added tests
1 parent 594a047 commit 03d1707

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sqlmock_go18_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,12 @@ func TestPingExpectationsContextTimeout(t *testing.T) {
642642
}
643643
}
644644

645+
type failArgument struct{}
646+
647+
func (f failArgument) Match(_ driver.Value) bool {
648+
return false
649+
}
650+
645651
func Test_sqlmock_Exec(t *testing.T) {
646652
db, mock, err := New()
647653
if err != nil {
@@ -652,7 +658,12 @@ func Test_sqlmock_Exec(t *testing.T) {
652658

653659
expected := NewResult(1, 1)
654660
mock.ExpectExec("SELECT (.+) FROM users WHERE (.+)").
655-
WillReturnResult(expected)
661+
WillReturnResult(expected).
662+
WithArgs("test")
663+
664+
mock.ExpectExec("SELECT (.+) FROM animals WHERE (.+)").
665+
WillReturnError(errors.New("matcher %T could not match %d argument %T - %+v")).
666+
WithArgs(failArgument{})
656667

657668
result, err := mock.(*sqlmock).Exec(query, []driver.Value{"test"})
658669
if err != nil {
@@ -663,6 +674,12 @@ func Test_sqlmock_Exec(t *testing.T) {
663674
t.Errorf("Results are not equal. Expected: %v, Actual: %v", expected, result)
664675
return
665676
}
677+
678+
_, err = mock.(*sqlmock).Exec(query, []driver.Value{failArgument{}})
679+
if err == nil {
680+
t.Errorf("error expected")
681+
return
682+
}
666683
}
667684

668685
func Test_sqlmock_Query(t *testing.T) {

0 commit comments

Comments
 (0)