-
-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to expect a prepared insert ? #71
Comments
Hi, you can look into the tests of sqlmock for more details. the error message says, that you must mock the result Exec should return func TestLogHistory(t *testing.T) {
var mock sqlmock.Sqlmock
var err error
db, mock, err = sqlmock.New()
if err != nil {
t.Fatal(err)
}
mock.ExpectPrepare("INSERT INTO").ExpectExec().WithArgs("2").WillReturnResult(sqlmock.NewResult(1, 1))
stmt, err := db.Prepare("INSERT INTO history VALUES(?)")
if err != nil {
panic(err)
}
if _, err := stmt.Exec("2"); err != nil {
t.Fatal(err)
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Fatal(err)
}
} Because it has to produce the result with a number off affected rows and last insert ID if available. |
omg wow, I'm such a doofus, thank you so much |
happens for everyone, cheers ;) |
@l3pp4rd I'm not able to use |
OK, found it in the tests |
I can't figure out how to setup the mock to expect an insert. Any tips ?
The text was updated successfully, but these errors were encountered: