Open davidxiao opened 4 years ago
many people are using gorm, I'm sure you are doing something wrong. you do not even check the errors. opening a gorm db may give you an error
source code was simplified for demo, but added it to avoid confusion It seems related to transaction according to error message? that's why create the ticket, but not so sure.
call to database transaction Begin, was not expected
Have you tried to remove mock.ExpectBegin()
and mock.ExpectCommit()
?
I have the same error as you, but mine is an update query. Cannot figure out which part goes wrong ;)
You can try add
tx := Db.Begin()
if tx.Error != nil {
return tx.Error
}
and
return tx.Commit().Error
To your recordStats
transaction
What version of Go are you using (go version)? go version go1.14 darwin/amd64
github.com/DATA-DOG/go-sqlmock v1.4.1
github.com/jinzhu/gorm v1.9.12
Which database and its version are you using? postgres 10.11
description? Basically it's very simple from readme of https://github.com/DATA-DOG/go-sqlmock, with little change, I tried to mock in project, but got the below issue, and so copied the sample from sqlmock repo, and tried, and got the same, Can someone pls help? didn't use gorm and sqlmock before. thanks very much,
Please provide a complete runnable program to reproduce your issue. IMPORTANT