I have the code:
func (db *DB) Confirm(hash string) error {
var authInfo config.AuthConfirmation
row := db.QueryRow("SELECT * FROM auth_confirmation WHERE hash = $1", hash)
err := row.Scan(&authInfo.Email, &authInfo.Hash, &authInfo.Deadline)
if err != nil {
return err
}
// some other logic
I want to test this function using sql-mock
hash := "$2a$04$oA1axCBmazUBEzNl0KjrHuVy.ssgX4oySz/MKZGdoUX5h7vim.TfG"
row := mock.NewRows([]string{"email", "hash", "deadline"}).
AddRow("example@ex.com", hash, time.Now().Add(time.Hour))
mock.ExpectQuery("SELECT * FROM auth_confirmation").
WithArgs(hash).WillReturnRows(row)
But Scan returns error:
Query: could not match actual sql: "SELECT * FROM auth_confirmation WHERE hash = $1" with expected regexp "SELECT * FROM auth_confirmation"
What mistakes I did?