DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.09k stars 408 forks source link

Getting 'Query: could not match actual sql' on identical queries #303

Closed z4id closed 1 year ago

z4id commented 1 year ago

Operating system and Go Version

Issue

Getting error "Query: could not match actual sql" even though both strings are identical. (compared via another tool)

rows, err := d.DB.Query(query)

P.S:: Same code is working on other systems. Not sure whether its related to different hardware architecture or OS.

Reproduction steps

SQL query is mocked like this:

mock.ExpectQuery(regexp.QuoteMeta(expectedQuery)).WillReturnRows(rows)

Expected Result

There should be no error.

Actual Result

Query: could not match actual sql:

thecodecafe commented 1 year ago

Hey @z4id were you able to figure this issue out? Experiencing this as well.

See the error I get below. Query: could not match actual sql:

SELECT * FROM "accounts" WHERE created_at > 1970-01-01 01:00:00 +0100 WAT AND "accounts"."deleted_at" IS NULL ORDER BY created_at DESC LIMIT 100

with expected regexp

SELECT * FROM "accounts" WHERE created_at > 1970-01-01 01:00:00 +0100 WAT AND "accounts"."deleted_at" IS NULL ORDER BY created_at DESC LIMIT 100
thecodecafe commented 1 year ago

@z4id found a solution here in another issue.