Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gorm v2.0 unit testing with sqlmock does not work with Postgres uint #7042

Open
thomasmodeneis opened this issue May 31, 2024 · 1 comment
Open
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@thomasmodeneis
Copy link

thomasmodeneis commented May 31, 2024

GORM Playground Link

go-gorm/playground#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.

@thomasmodeneis
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

2 participants