Files
llmgw/internal/store/unique_test.go
T
Ilker ManapandClaude Opus 5.5 8957db30a2 Recognise a duplicate sign-up on PostgreSQL, and say what to do
A taken address on PostgreSQL fell through to a generic error, because
the store looked for SQLite's "UNIQUE". It checks code 23505 too. The
done page tells someone whose address had an account to sign in or ask
for a reset, without saying which case it was; other failures give a
logged reference.

Refs #2 (item 6).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-01 12:15:37 +02:00

31 lines
993 B
Go

package store
import (
"errors"
"fmt"
"testing"
"github.com/jackc/pgx/v5/pgconn"
)
func TestADuplicateIsRecognisedOnEitherDatabase(t *testing.T) {
for _, c := range []struct {
name string
err error
want bool
}{
{"sqlite", errors.New("constraint failed: UNIQUE constraint failed: users.email (2067)"), true},
// What pgx returns, wrapped as database/sql passes it on: "unique"
// in lower case, which a check for "UNIQUE" missed.
{"postgres", fmt.Errorf("exec: %w", &pgconn.PgError{Code: "23505",
Message: `duplicate key value violates unique constraint "users_email_key"`}), true},
{"postgres, as text", errors.New(`ERROR: duplicate key value violates unique constraint "users_email_key" (SQLSTATE 23505)`), true},
{"another postgres error", &pgconn.PgError{Code: "23502", Message: "null value in column"}, false},
{"nothing", nil, false},
} {
if got := isUniqueViolation(c.err); got != c.want {
t.Errorf("%s: %v, want %v", c.name, got, c.want)
}
}
}