GORM Playground Link
https://github.com/go-gorm/playground/pull/738
Description
I was reading up the now closed issue for a reference on how to use github.com/DATA-DOG/go-sqlmock with gorm.
The example provided works, however if you are using the ID field with uint as per the docs then you will face the issue: call to Rollback transaction, was not expected, next expectation is: ExpectedExec => expecting Exec or ExecContext which.
The workaround is to set the ID as string as per the example in the referred issue above, (you can either set or not the the ID, the effect is the same). That will persist the data but with the caveat that you wont get the ID back since the ORM will not return the ID.
I am currently not sure how to deal with this error and it seems like this is an issue that dates back to 2020.
I've added the failing and working test via the playground link as requested.
I would appreciate a swiftly follow up here.
Thank you.
Comment From: thomasmodeneis
Hello, I've found another work around, If we simplify the assertion then it works:
s.mock.ExpectQuery(`INSERT INTO "students" (.+) VALUES (.+) RETURNING "id"`).WillReturnRows(addRow)
Still I dont understand why ExpectExec fails.