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

Problem while INSERTING #224

Open
RajivBobble opened this issue May 8, 2020 · 1 comment
Open

Problem while INSERTING #224

RajivBobble opened this issue May 8, 2020 · 1 comment

Comments

@RajivBobble
Copy link

This is the Error I'm getting
all expectations were already fulfilled, call to database transaction Begin was not expected

I have a code in my go lang

var userRoles models.UserRole
userRoles.UserID = userID
userRoles.RoleID = id
db.Create(&userRoles)

And This Query is generated
INSERT INTO user_roles (user_id,role_id,created_at,updated_at) VALUES (1,1,2020-05-08 13:35:59,2020-05-08 13:35:59)
While mocking with this code with WithArgs() and Without WithArgs()

mock.ExpectBegin()
mock.ExpectExec("INSERT INTO \"u").WithArgs(1, 1, sqlmock.AnyArg(), sqlmock.AnyArg()).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

I have also tried this
mock.ExpectQuery("INSERT INTO user.*").WithArgs(1,1,sqlmock.AnyArg()sqlmock.AnyArg()).WillReturnRows(row)
Getting same error

@rmulley
Copy link
Collaborator

rmulley commented Sep 15, 2020

@RajivBobble I'm happy to help, but I'll need a more complete example. Could you provide more of the relevant code?

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

No branches or pull requests

2 participants