Documentation
¶
Overview ¶
Package testmode provides functions to set special modes for tests, allowing to use actual Postgres or SQLite file for testing, especially for development purposes. Important: It should be used only in LOCAL tests. Calls of SetPostgresMode and SetFileSQLiteMode should not be committed.
Index ¶
- Constants
- func CheckFileSQLiteMode() bool
- func CheckPostgresContainerMode() bool
- func CheckPostgresMode() (ok bool, dbName string)
- func CleanDatabaseSchema(t testing.TB, container *TestContainer)
- func DevelopmentOnly_SetFileSQLiteMode(t testing.TB)
- func DevelopmentOnly_SetPostgresMode(t testing.TB)
- func DevelopmentOnly_SetPostgresModeWithName(t testing.TB, dbName string)
- func IsDockerAvailable() bool
- type TestContainer
Constants ¶
const ( // EnvDBMode is the environment variable to set the test database mode EnvDBMode = "TEST_DB_MODE" // EnvDBName is the environment variable to set the test database name EnvDBName = "TEST_DB_NAME" // EnvDBHost is the environment variable to set the test database host EnvDBHost = "TEST_DB_HOST" // EnvDBPort is the environment variable to set the test database port EnvDBPort = "TEST_DB_PORT" // PostgresContainerMode is the mode to use a PostgreSQL testcontainer for testing PostgresContainerMode = "postgres-container" // PostgresMode is the mode to use actual Postgres for testing PostgresMode = "postgres" // SQLiteFileMode is the mode to use SQLite file for testing SQLiteFileMode = "file" // DefaultPostgresName is the default database name for PostgreSQL DefaultPostgresName = "postgres" // DefaultPostgresUser is the default database user for PostgreSQL DefaultPostgresUser = "postgres" // DefaultPostgresPass is the default database password for PostgreSQL DefaultPostgresPass = "postgres" )
Variables ¶
This section is empty.
Functions ¶
func CheckFileSQLiteMode ¶
func CheckFileSQLiteMode() bool
CheckFileSQLiteMode checks if the test mode is set to use SQLite file
func CheckPostgresContainerMode ¶
func CheckPostgresContainerMode() bool
CheckPostgresContainerMode checks if the test mode is set to use PostgreSQL container
func CheckPostgresMode ¶
CheckPostgresMode checks if the test mode is set to use actual Postgres and returns the database name
func CleanDatabaseSchema ¶
func CleanDatabaseSchema(t testing.TB, container *TestContainer)
CleanDatabaseSchema resets the database schema for a fresh test
func DevelopmentOnly_SetFileSQLiteMode ¶
DevelopmentOnly_SetFileSQLiteMode sets the test mode to use SQLite file
func DevelopmentOnly_SetPostgresMode ¶
DevelopmentOnly_SetPostgresMode sets the test mode to use actual Postgres
func DevelopmentOnly_SetPostgresModeWithName ¶
DevelopmentOnly_SetPostgresModeWithName sets the test mode to use actual Postgres and sets the database name
func IsDockerAvailable ¶ added in v1.1.0
func IsDockerAvailable() bool
IsDockerAvailable checks if Docker daemon is running and accessible
Types ¶
type TestContainer ¶
type TestContainer struct {
Container testcontainers.Container
Host string
Port string
}
TestContainer represents a running test container
func StartPostgresContainer ¶
func StartPostgresContainer(t testing.TB) *TestContainer
StartPostgresContainer starts a PostgreSQL container and returns connection details