Skip to content

Catch 22 situation regarding regex matching vs exact query matching. #348

@RedMarcher

Description

@RedMarcher

Question

This is the actual code:
err = c.database.QueryRowContext(ctx, "SELECT COUNT(*) FROM user_credentials WHERE user_id = $1", passwordUpdateRequest.UserId).Scan(&count)

This is mock:
suite.dbMock.ExpectQuery(SELECT COUNT(*) FROM user_credentials WHERE user_id = ?).
WithArgs(tc.userID).
WillReturnRows(suite.dbMock.NewRows([]string{"count"}).AddRow(1))

When its run, this error occurs:
failed to check user credentials: Query: error parsing regexp: missing argument to repetition operator: *

When the * is escaped,
failed to check user credentials: Query: could not match actual sql: "SELECT COUNT(*) FROM user_credentials WHERE user_id = $1" with expected regexp "SELECT COUNT(*) FROM user_credentials WHERE user_id = ?"

So it seems there's no way of satisfying this, I tried many other escape methods as well but they all cause the second error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions