diff --git a/storage/testdb/testdb.go b/storage/testdb/testdb.go index 28d662ae77..333ca22998 100644 --- a/storage/testdb/testdb.go +++ b/storage/testdb/testdb.go @@ -62,17 +62,17 @@ var ( trillianCRDBSchema = testonly.RelativeToPackage("../crdb/schema/storage.sql") ) -// TestDBDriverName is the name of a database driver. -type TestDBDriverName string +// DriverName is the name of a database driver. +type DriverName string const ( // DriverMySQL is the identifier for the MySQL storage driver. - DriverMySQL TestDBDriverName = "mysql" + DriverMySQL DriverName = "mysql" // DriverCockroachDB is the identifier for the CockroachDB storage driver. - DriverCockroachDB TestDBDriverName = "cockroachdb" + DriverCockroachDB DriverName = "cockroachdb" ) -var driverMapping = map[TestDBDriverName]storageDriverInfo{ +var driverMapping = map[DriverName]storageDriverInfo{ DriverMySQL: { sqlDriverName: "mysql", schema: trillianMySQLSchema, @@ -152,7 +152,7 @@ func CockroachDBAvailable() bool { return dbAvailable(DriverCockroachDB) } -func dbAvailable(driver TestDBDriverName) bool { +func dbAvailable(driver DriverName) bool { driverName := driverMapping[driver].sqlDriverName uri := driverMapping[driver].uriFunc() db, err := sql.Open(driverName, uri) @@ -188,7 +188,7 @@ func SetFDLimit(uLimit uint64) error { // using the DB, the caller should not continue to use the returned DB after // calling this function as it may, for example, delete the underlying // instance. -func newEmptyDB(ctx context.Context, driver TestDBDriverName) (*sql.DB, func(context.Context), error) { +func newEmptyDB(ctx context.Context, driver DriverName) (*sql.DB, func(context.Context), error) { if err := SetFDLimit(2048); err != nil { return nil, nil, err } @@ -231,7 +231,7 @@ func newEmptyDB(ctx context.Context, driver TestDBDriverName) (*sql.DB, func(con // NewTrillianDB creates an empty database with the Trillian schema. The database name is randomly // generated. // NewTrillianDB is equivalent to Default().NewTrillianDB(ctx). -func NewTrillianDB(ctx context.Context, driver TestDBDriverName) (*sql.DB, func(context.Context), error) { +func NewTrillianDB(ctx context.Context, driver DriverName) (*sql.DB, func(context.Context), error) { db, done, err := newEmptyDB(ctx, driver) if err != nil { return nil, nil, err @@ -278,6 +278,7 @@ func SkipIfNoMySQL(t *testing.T) { t.Logf("Test MySQL available at %q", mysqlURI()) } +// SkipIfNoCockroachDB is a test helper that skips tests that require a local CockroachDB. func SkipIfNoCockroachDB(t *testing.T) { t.Helper() if !CockroachDBAvailable() { diff --git a/testonly/integration/registry.go b/testonly/integration/registry.go index 2610cf42c7..dc9a0fb9a9 100644 --- a/testonly/integration/registry.go +++ b/testonly/integration/registry.go @@ -26,7 +26,7 @@ import ( // NewRegistryForTests returns an extension.Registry for integration tests. // Callers should call the returned cleanup function when they're finished // with the registry and its contents. -func NewRegistryForTests(ctx context.Context, driver testdb.TestDBDriverName) (extension.Registry, func(context.Context), error) { +func NewRegistryForTests(ctx context.Context, driver testdb.DriverName) (extension.Registry, func(context.Context), error) { db, done, err := testdb.NewTrillianDB(ctx, driver) if err != nil { return extension.Registry{}, nil, err