DATA-DOG / go-sqlmock

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

Invalid regex not reported as so #197

Open nazneen84 opened 4 years ago

nazneen84 commented 4 years ago

I tried a nested query. Instead of letting me know the regex is not valid or pointing out differences in the string literal versus the regex pattern, it said query not expected and unable to match actual versus expected query respectively.

Please clarify the regex was invalid in the panic message or a compile time warning please.

Stack overflow question here: https://stackoverflow.com/questions/58142191/call-to-query-with-args-was-not-expected-in-go-sqlmock-for-compound-sql-quer/58160875#58160875.

Example of working query:

sqlMock.ExpectQuery("SELECT EXISTS \\( SELECT 1 FROM information_schema\\.tables WHERE table_schema = 'public' AND table_name = 'myTable3' \\);").
        WillReturnRows(existsRows)

Example of Invalid query unable to match:

sqlMock.ExpectQuery("SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'myTable3' );").
        WillReturnRows(existsRows)

Example of invalid regex query skipped in evaulation:

sqlMock.ExpectQuery("SELECT EXISTS \\( SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'myTable3' \\);").
        WillReturnRows(existsRows)
l3pp4rd commented 4 years ago

Hi, probably should follow as an improvement to #158 in order to tell whether sql was not matched