DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.02k stars 406 forks source link

call to ExecQuery ... was not expected; call to Rollback transaction was not expecte in gorm with postgres #246

Closed majidbl closed 2 months ago

majidbl commented 3 years ago

call to ExecQuery 'INSERT INTO "users" ("id","user_name","pass_word","email","role","name","created_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8)' with args [{Name: Ordinal:1 Value:a8813f4a-bd82-4dd2-bdd9-fbcf0aa7787f} {Name: Ordinal:2 Value:test} {Name: Ordinal:3 Value:12345} {Name: Ordinal:4 Value:testemail} {Name: Ordinal:5 Value:admin} {Name: Ordinal:6 Value:test} {Name: Ordinal:7 Value:2020-11-18 16:36:03.948311091 +0330 +0330 m=+0.005700519} {Name: Ordinal:8 Value:2020-11-18 16:36:03.94831117 +0330 +0330 m=+0.005700600}] was not expected; call to Rollback transaction was not expected [0.300ms] [rows:0] INSERT INTO "users" ("id","user_name","pass_word","email","role","name","created_at","updated_at") VALUES ('a8813f4a-bd82-4dd2-bdd9-fbcf0aa7787f','test','12345','testemail','admin','test','2020-11-18 16:36:03.948','2020-11-18 16:36:03.948') --- FAIL: TestSignUp (0.00s) postgersql_test.go:96: Failed to insert to gorm db, got error: call to ExecQuery 'INSERT INTO "users" ("id","user_name","pass_word","email","role","name","created_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8)' with args [{Name: Ordinal:1 Value:a8813f4a-bd82-4dd2-bdd9-fbcf0aa7787f} {Name: Ordinal:2 Value:test} {Name: Ordinal:3 Value:12345} {Name: Ordinal:4 Value:testemail} {Name: Ordinal:5 Value:admin} {Name: Ordinal:6 Value:test} {Name: Ordinal:7 Value:2020-11-18 16:36:03.948311091 +0330 +0330 m=+0.005700519} {Name: Ordinal:8 Value:2020-11-18 16:36:03.94831117 +0330 +0330 m=+0.005700600}] was not expected; call to Rollback transaction was not expected postgersql_test.go:101: Failed to meet expectations, got error: there is a remaining expectation which was not matched: ExpectedQuery => expecting Query, QueryContext or QueryRow which:

ehduardu commented 2 years ago

I have the same issue

nidyaonur commented 2 years ago

I also have the same issue

yaseenisolated commented 2 years ago

Looking at your error it has

call to ExecQuery 'INSERT INTO "users" ("id","user_name","pass_word","email","role","name","created_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8)' ...

expecting Query, QueryContext or QueryRow which:

  • matches sql: 'INSERT INTO "users" ("id","user_name", "pass_word","email","role","name","created_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "users"."id";'

The query your code is running does not end in the 'RETURNING "users"."id";' that exists in your test.