mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2025-01-24 03:16:17 +02:00
refers to #37
This commit is contained in:
parent
55a0289da5
commit
b465b1f024
@ -340,7 +340,6 @@ func (c *sqlmock) Query(query string, args []driver.Value) (rw driver.Rows, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer expected.Unlock()
|
defer expected.Unlock()
|
||||||
expected.triggered = true
|
|
||||||
|
|
||||||
if !expected.queryMatches(query) {
|
if !expected.queryMatches(query) {
|
||||||
return nil, fmt.Errorf("query '%s', does not match regex [%s]", query, expected.sqlRegex.String())
|
return nil, fmt.Errorf("query '%s', does not match regex [%s]", query, expected.sqlRegex.String())
|
||||||
@ -358,6 +357,7 @@ func (c *sqlmock) Query(query string, args []driver.Value) (rw driver.Rows, err
|
|||||||
return nil, fmt.Errorf("query '%s' with args %+v, must return a database/sql/driver.rows, but it was not set for expectation %T as %+v", query, args, expected, expected)
|
return nil, fmt.Errorf("query '%s' with args %+v, must return a database/sql/driver.rows, but it was not set for expectation %T as %+v", query, args, expected, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expected.triggered = true
|
||||||
return expected.rows, err
|
return expected.rows, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,3 +658,35 @@ func ExampleSqlmock_goroutines() {
|
|||||||
}
|
}
|
||||||
// Output:
|
// Output:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// False Positive - passes despite mismatched Exec
|
||||||
|
// see #37 issue
|
||||||
|
func TestRunExecsWithOrderedShouldNotMeetAllExpectations(t *testing.T) {
|
||||||
|
db, dbmock, _ := New()
|
||||||
|
dbmock.ExpectExec("THE FIRST EXEC")
|
||||||
|
dbmock.ExpectExec("THE SECOND EXEC")
|
||||||
|
|
||||||
|
_, _ = db.Exec("THE FIRST EXEC")
|
||||||
|
_, _ = db.Exec("THE WRONG EXEC")
|
||||||
|
|
||||||
|
err := dbmock.ExpectationsWereMet()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("was expecting an error, but there wasn't any")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// False Positive - passes despite mismatched Exec
|
||||||
|
// see #37 issue
|
||||||
|
func TestRunQueriesWithOrderedShouldNotMeetAllExpectations(t *testing.T) {
|
||||||
|
db, dbmock, _ := New()
|
||||||
|
dbmock.ExpectQuery("THE FIRST EXEC")
|
||||||
|
dbmock.ExpectQuery("THE SECOND EXEC")
|
||||||
|
|
||||||
|
_, _ = db.Query("THE FIRST EXEC")
|
||||||
|
_, _ = db.Query("THE WRONG EXEC")
|
||||||
|
|
||||||
|
err := dbmock.ExpectationsWereMet()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("was expecting an error, but there wasn't any")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user