Documentation
¶
Overview ¶
Package helpers provides testing utilities for database connections, environment setup, and test data management for Scanorama integration tests.
Package helpers provides test helper functions for Scanorama
Index ¶
- func CreateTestDatabase(config *DatabaseConfig) error
- func EnsureTestSchema(ctx context.Context, database *db.DB) error
- func GetDatabaseStatus() string
- func IsDatabaseAvailable(config *DatabaseConfig) bool
- func IsPostgreSQLRunning(port int) bool
- func WaitForDatabase(config *DatabaseConfig, timeout time.Duration) error
- type DatabaseConfig
- type TestEnvironment
- type TestService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTestDatabase ¶
func CreateTestDatabase(config *DatabaseConfig) error
CreateTestDatabase creates a test database if it doesn't exist.
func EnsureTestSchema ¶
EnsureTestSchema ensures the database schema is set up for testing.
func GetDatabaseStatus ¶
func GetDatabaseStatus() string
GetDatabaseStatus returns a human-readable status of database availability.
func IsDatabaseAvailable ¶
func IsDatabaseAvailable(config *DatabaseConfig) bool
IsDatabaseAvailable checks if a database is available and accessible.
func IsPostgreSQLRunning ¶
IsPostgreSQLRunning checks if PostgreSQL is running on the given port.
func WaitForDatabase ¶
func WaitForDatabase(config *DatabaseConfig, timeout time.Duration) error
WaitForDatabase waits for database to become available with timeout.
Types ¶
type DatabaseConfig ¶
type DatabaseConfig struct {
Host string
Port int
Database string
Username string
Password string
SSLMode string
}
DatabaseConfig represents a database configuration for testing.
func ConnectToTestDatabase ¶
ConnectToTestDatabase attempts to connect to an available test database.
func GetAvailableDatabase ¶
func GetAvailableDatabase() (*DatabaseConfig, error)
GetAvailableDatabase returns the first available database from the test configurations.
func GetTestDatabaseConfigs ¶
func GetTestDatabaseConfigs() []DatabaseConfig
GetTestDatabaseConfigs returns a list of database configurations to try for testing. It tries test database first, then development database as fallback.
type TestEnvironment ¶
type TestEnvironment struct {
Services map[string]TestService
ContainerName string
Timeout int
RequireAll bool
}
TestEnvironment defines the test environment configuration.
func DefaultTestEnvironment ¶
func DefaultTestEnvironment() *TestEnvironment
DefaultTestEnvironment returns the default test environment configuration.
func (*TestEnvironment) CheckService ¶
CheckService attempts to connect to a service with retries.
func (*TestEnvironment) GetAvailableServices ¶
func (env *TestEnvironment) GetAvailableServices(t *testing.T) []string
GetAvailableServices returns a list of available service ports.
func (*TestEnvironment) SetupTestEnvironment ¶
func (env *TestEnvironment) SetupTestEnvironment(t *testing.T) bool
SetupTestEnvironment returns true if all required services are available, false otherwise.
type TestService ¶
TestService defines a service available in the Docker test environment.