testmode

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
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

func CheckPostgresMode() (ok bool, dbName string)

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

func DevelopmentOnly_SetFileSQLiteMode(t testing.TB)

DevelopmentOnly_SetFileSQLiteMode sets the test mode to use SQLite file

func DevelopmentOnly_SetPostgresMode

func DevelopmentOnly_SetPostgresMode(t testing.TB)

DevelopmentOnly_SetPostgresMode sets the test mode to use actual Postgres

func DevelopmentOnly_SetPostgresModeWithName

func DevelopmentOnly_SetPostgresModeWithName(t testing.TB, dbName string)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL