Documentation
¶
Overview ¶
Package storage contains containers that can be used to test all available data stores.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupPostgresContainer ¶ added in v1.15.0
func CleanupPostgresContainer()
CleanupPostgresContainer removes the shared postgres test container. It should be called from TestMain after all tests in a package have finished.
func NewMySQLTestContainer ¶ added in v0.2.3
func NewMySQLTestContainer() *mySQLTestContainer
NewMySQLTestContainer returns an implementation of the DatastoreTestContainer interface for MySQL.
func NewSqliteTestContainer ¶ added in v1.6.1
func NewSqliteTestContainer() *sqliteTestContainer
NewSqliteTestContainer returns an implementation of the DatastoreTestContainer interface for SQLite.
Types ¶
type DatastoreTestContainer ¶ added in v0.2.0
type DatastoreTestContainer interface {
// GetConnectionURI returns a connection string to the datastore instance running inside
// the container.
GetConnectionURI(includeCredentials bool) string
// GetDatabaseSchemaVersion returns the last migration applied (e.g. 3) when the container was created
GetDatabaseSchemaVersion() int64
GetUsername() string
GetPassword() string
// CreateSecondary creates a secondary datastore if supported.
// Returns an error if the operation fails or if the datastore doesn't support secondary datastores.
CreateSecondary(t testing.TB) error
// GetSecondaryConnectionURI returns the connection URI for the secondary datastore if one exists.
// Returns an empty string if no secondary datastore exists.
GetSecondaryConnectionURI(includeCredentials bool) string
}
DatastoreTestContainer represents a runnable container for testing specific datastore engines.
func RunDatastoreTestContainer ¶ added in v0.2.0
func RunDatastoreTestContainer(t testing.TB, engine string) DatastoreTestContainer
RunDatastoreTestContainer constructs and runs a specific DatastoreTestContainer for the provided datastore engine. If applicable, it also runs all existing database migrations. The resources used by the test engine will be cleaned up after the test has finished.
NOTE: PostgreSQL uses a shared container across tests, so it is not automatically cleaned up after each test.
func RunPostgresTestContainer ¶ added in v1.15.0
func RunPostgresTestContainer(t testing.TB) DatastoreTestContainer