Vivek Srivastava
Vivek Srivastava

Reputation: 569

Getting error in sqlmock for GoLang

I am writing test cases for a GoLang application and i am using sqlmock for mocking the SQL queries but i am getting following error while executing go test

Params: [ call to query , was not expected, next expectation is: ExpectedBegin => expecting database transaction Begin]

Any idea on this?

Upvotes: 1

Views: 5110

Answers (3)

Alveona
Alveona

Reputation: 978

I had same issue, because I used NamedExec (not NamedQuery) to perform my update, but was mocking ExpectQuery in test

So,
if you have expression (i.e. use UPDATE or INSERT), you should use ExpectExec
if you have query (i.e. use SELECT), you should use ExpectQuery

It's obvious, but I stuck with it for couple of hours

Upvotes: 0

Proton14
Proton14

Reputation: 11

sqlmock expected a begin, but instead got something else. Show the function and test here for more info.

Upvotes: 1

The error message means some SQL query was called which was not mocked.

Upvotes: 0

Related Questions