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
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,
call to database transaction Begin, was not expected, next expectation is: ExpectedExec => expecting Exec or ExecContext which
matches sql: 'UPDATE products'
is without arguments
should return Result having:
LastInsertId: 1
RowsAffected: 1
Please provide a complete runnable program to reproduce your issue. IMPORTANT
import (
"testing"
"github.com/DATA-DOG/go-sqlmock"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
// a successful case
func TestWithGorm(t *testing.T) {
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
gDB, err := gorm.Open("postgres", db)
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
gDB.LogMode(true)
defer db.Close()
// mock.MatchExpectationsInOrder(false)// adding this line doesn't help,similar error
mock.ExpectBegin()
mock.ExpectExec("INSERT products").WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("INSERT INTO product_viewers").WithArgs(2, 3).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()
// now we execute our method
if err = recordStats(gDB, 2, 3); err != nil {
t.Errorf("error was not expected while updating stats: %s", err)
}
// we make sure that all expectations were met
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expectations: %s", err)
}
}
The text was updated successfully, but these errors were encountered:
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.
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
The text was updated successfully, but these errors were encountered: