refac: migration crash, real-database tests, site deleted during create, ruels out of the repo, lists
This commit is contained in:
1 parent
680b9a1308
commit
9d284e65a9
62 files changed
+1858
-987
No files matched your search
@@ -76,3 +76,32 @@ func TestTransactorClassifiesLockContention(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestDriverUniqueViolation(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
driver string
|
||||
err error
|
||||
want bool
|
||||
}{
|
||||
{"sqlite unique index", database.DriverSQLite, codedSQLiteError{2067}, true},
|
||||
{"sqlite primary key", database.DriverSQLite, fmt.Errorf("wrapped: %w", codedSQLiteError{1555}), true},
|
||||
{"sqlite not null", database.DriverSQLite, codedSQLiteError{1299}, false},
|
||||
{"sqlite busy", database.DriverSQLite, codedSQLiteError{5}, false},
|
||||
{"sqlite plain error", database.DriverSQLite, errors.New("UNIQUE constraint failed"), false},
|
||||
{"mysql duplicate entry", database.DriverMySQL, &mysqldriver.MySQLError{Number: 1062}, true},
|
||||
{"mysql duplicate entry with key name", database.DriverMySQL, fmt.Errorf("wrapped: %w", &mysqldriver.MySQLError{Number: 1586}), true},
|
||||
{"mysql deadlock", database.DriverMySQL, &mysqldriver.MySQLError{Number: 1213}, false},
|
||||
{"postgres unique violation", database.DriverPostgres, &pgconn.PgError{Code: "23505"}, true},
|
||||
{"postgres foreign key violation", database.DriverPostgres, &pgconn.PgError{Code: "23503"}, false},
|
||||
{"unknown driver", "oracle", &pgconn.PgError{Code: "23505"}, false},
|
||||
{"nil error", database.DriverPostgres, nil, false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
if got := database.IsUniqueViolationFor(c.driver, c.err); got != c.want {
|
||||
t.Errorf("got %v, want %v", got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user