You've already forked go-sqlxmock
mirror of
https://github.com/zhashkevych/go-sqlxmock.git
synced 2025-11-29 21:57:41 +02:00
Mikemacd patch 1 (#2)
* Update sqlmock.go Permit prepares to obey MatchExpectationsInOrder flag, allowing prepared statements to be prepared in a different order than they were added to the expectations. * Update sqlmock_test.go Add test case for unordered prepared statements.
This commit is contained in:
committed by
GitHub
parent
18ab7ac1c7
commit
ca83e31de6
@@ -354,6 +354,48 @@ func TestPreparedQueryExecutions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestUnorderedPreparedQueryExecutions(t *testing.T) {
|
||||
t.Parallel()
|
||||
db, mock, err := New()
|
||||
if err != nil {
|
||||
t.Errorf("an error '%s' was not expected when opening a stub database connection", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
mock.MatchExpectationsInOrder(false)
|
||||
|
||||
mock.ExpectPrepare("SELECT (.+) FROM articles WHERE id = ?").
|
||||
ExpectQuery().
|
||||
WithArgs(5).
|
||||
WillReturnRows(
|
||||
NewRows([]string{"id", "title"}).FromCSVString("5,The quick brown fox"),
|
||||
)
|
||||
mock.ExpectPrepare("SELECT (.+) FROM authors WHERE id = ?").
|
||||
ExpectQuery().
|
||||
WithArgs(1).
|
||||
WillReturnRows(
|
||||
NewRows([]string{"id", "title"}).FromCSVString("1,Betty B."),
|
||||
)
|
||||
|
||||
var id int
|
||||
var name string
|
||||
|
||||
stmt, err := db.Prepare("SELECT id, name FROM authors WHERE id = ?")
|
||||
if err != nil {
|
||||
t.Errorf("error '%s' was not expected while creating a prepared statement", err)
|
||||
}
|
||||
|
||||
err = stmt.QueryRow(1).Scan(&id, &name)
|
||||
if err != nil {
|
||||
t.Errorf("error '%s' was not expected querying row from statement and scanning", err)
|
||||
}
|
||||
|
||||
if name != "Betty B." {
|
||||
t.Errorf("expected mocked name to be 'Betty B.', but got '%s' instead", name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnexpectedOperations(t *testing.T) {
|
||||
t.Parallel()
|
||||
db, mock, err := New()
|
||||
|
||||
Reference in New Issue
Block a user