DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.16k stars 407 forks source link

Arguments Error #264

Closed afzalabbasi closed 5 months ago

afzalabbasi commented 3 years ago

hey All mock.ExpectExec("SELECT FROM permission WHERE roleid = $1").WithArgs(2) this is my mock queey i just compare that one with the original query which one is db.Get(&programinfo, "SELECT FROM permission WHERE roleid = $1", roleid) but i found that error call to Query 'SELECT * FROM permission WHERE roleid = $1' with args [{Name: Ordinal:1 Value:2}], was not expected, next expectation is: ExpectedExec => expecting Exec or ExecContext which:

dolmen commented 2 years ago

Please post some example code working on the Go Playground. Here is a template.

ShuaoZhang commented 2 years ago

Same issue, have you fixed it?

bekha-io commented 11 months ago

Facing same issue. Any updates?

diegommm commented 5 months ago

Hi @afzalabbasi! It looks like you're using ExpectExec for a SELECT, which should typically be modeled with a Query, QueryContext, QueryRow, QueryRowContext. The code you provide is using a Get method, which is not part of the standard library's database/sql package, so it's harder to know what your Get method is doing. Maybe you're using a wrapper library like gorm or sqlx? If that's the case and your wrapper library is transalting to any of the 4 Query* methods then you should use ExpectQuery instead of ExpectExec.

I hope that helps, closing as this seems related to usage of an external library. If the problem persists, reopen and provide the following information:

Thank you!