You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, you are not doing it right in this case. The previous issue was valid, this isn't.
There are two ways, one to expect the query on that statement (which is more straightforward)
package main
import (
"testing""github.com/stretchr/testify/assert"
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
)
funcTestPrepare(t*testing.T) {
db, mock, mErr:=sqlmock.New()
assert.NoError(t, mErr)
deferdb.Close()
mock.ExpectPrepare("^SELECT id FROM test WHERE id=\\$1$").ExpectQuery().WithArgs("2")
testFunction(db)
iferr:=mock.ExpectationsWereMet(); err!=nil {
t.Errorf("there were unfulfilled expections: %s", err)
}
}
or make a next expectation for query, by repeating the query string
package main
import (
"testing""github.com/stretchr/testify/assert"
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
)
funcTestPrepare(t*testing.T) {
db, mock, mErr:=sqlmock.New()
assert.NoError(t, mErr)
deferdb.Close()
mock.ExpectPrepare("^SELECT id FROM test WHERE id=\\$1$")
mock.ExpectQuery("^SELECT id FROM test WHERE id=\\$1$").WithArgs("2")
testFunction(db)
iferr:=mock.ExpectationsWereMet(); err!=nil {
t.Errorf("there were unfulfilled expections: %s", err)
}
}
Hi ,
The following test will fail:
If i replace the code with
and
everything runs as expected.
I'm i doing something wrong?
Thanks
The text was updated successfully, but these errors were encountered: