Documentation
¶
Overview ¶
Package drivertest is a conformance kit for database driver modules.
A driver module registers a UniqueViolationFunc, and pkg/db consults every registered classifier in turn. That design has one sharp edge: a classifier that answers true for an error it did not produce answers for ANOTHER engine, and the bug shows up as a wrong HTTP status on a deployment the author never tests. The checks here pin the properties that make consulting classifiers in turn safe.
A driver module runs it from its own test:
func TestConformance(t *testing.T) {
drivertest.VerifyClassifier(t, drivertest.Case{
Engine: "mysql",
Classify: isUniqueViolation,
Violation: &gomysql.MySQLError{Number: 1062},
NotViolation: []error{&gomysql.MySQLError{Number: 1452}},
})
}
Like backendtest for authentication backends (ADR-027), this exists so the contract is verified by the same suite everywhere rather than re-derived, approximately, in each module.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func VerifyClassifier ¶
VerifyClassifier runs the conformance checks against one driver's classifier.
Types ¶
type Case ¶
type Case struct {
// Engine is the database/sql driver name the module registers under.
Engine string
// Classify is the function the module passes to
// driver.RegisterUniqueViolation.
Classify driver.UniqueViolationFunc
// Violation is an error the driver produces for a unique or primary-key
// constraint. Prefer one obtained from the real driver; fabricate only
// when the driver's error type can be constructed honestly.
Violation error
// NotViolation lists errors from the SAME driver that are constraint
// failures of another kind — a foreign key, a NOT NULL. These are the
// cases that fail when a classifier is widened to "any constraint
// error", which would make a caller blame the wrong field.
NotViolation []error
}
Case describes one driver's classifier and the errors it must and must not claim.