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
I'm trying to mock out a piece of code which uses two prepared statements to execute a series of queries. However, sqlmock seems to get confused if I create my ExpectPrepares (A&B), then create my Expects (A&B), then execute my queries (A&B) against the Expects.
On the other hand, if I create ExpectPrepare (A), create Expect (A), query against Expect (A), and then repeat for B it works. Unfortunately, the product code I'm trying to mock out isn't amenable to this pattern.
the rows were not closed or garbage collected for the q1P.
in go sql standard library the connection is held on Rows until they are closed. So this blocks connection.
that is why, standard sql library tried to open another connection, then it fired a PrepareContext again to the sqlmock and then it failed, since we were expecting Query instead of Prepare.
I do not know why go does that, it has the TODO in the code to fix it there and call Preparer interface instead to sqlmock driver. we could then adjust it.
Now the only option would be to ignore that Prepare call if the expectation was already met, but in such case, we may also fail some tests where the second call to prepare was not expected.
Sadly I do not know how to fix this properly. But probably worth having this issue open for others to be aware of.
I do not have much free time these days, so if anyone could contribute, this would be helpful to the library
go version go1.14.2 darwin/amd64
github.com/DATA-DOG/go-sqlmock v1.4.1
I'm trying to mock out a piece of code which uses two prepared statements to execute a series of queries. However, sqlmock seems to get confused if I create my ExpectPrepares (A&B), then create my Expects (A&B), then execute my queries (A&B) against the Expects.
On the other hand, if I create ExpectPrepare (A), create Expect (A), query against Expect (A), and then repeat for B it works. Unfortunately, the product code I'm trying to mock out isn't amenable to this pattern.
Shouldn't all three cases in this example work?
https://play.golang.org/p/k-sxKxGnd0Q
The text was updated successfully, but these errors were encountered: