Documentation
¶
Index ¶
- Constants
- func CreateTempConfigWithContent(t *testing.T, configContent string) string
- func CreateTempPgctlConfig(t *testing.T, pgContainer *PostgreSQLContainer) string
- func CreateTempPgctlConfigForPublisherSubscriber(t *testing.T, publisher, subscriber *PostgreSQLContainer) string
- func SetupPublisherSubscriberContainers(ctx context.Context, t *testing.T) (*PostgreSQLContainer, *PostgreSQLContainer)
- type PgctlExecutor
- type PgctlResult
- func (r *PgctlResult) AssertDurationLessThan(t *testing.T, maxDuration time.Duration) *PgctlResult
- func (r *PgctlResult) AssertExitCode(t *testing.T, expectedCode int) *PgctlResult
- func (r *PgctlResult) AssertFailure(t *testing.T) *PgctlResult
- func (r *PgctlResult) AssertStderrContains(t *testing.T, text string) *PgctlResult
- func (r *PgctlResult) AssertStderrEmpty(t *testing.T) *PgctlResult
- func (r *PgctlResult) AssertStdoutContains(t *testing.T, text string) *PgctlResult
- func (r *PgctlResult) AssertStdoutContainsOrContains(t *testing.T, text string, text2 string) *PgctlResult
- func (r *PgctlResult) AssertStdoutEmpty(t *testing.T) *PgctlResult
- func (r *PgctlResult) AssertSuccess(t *testing.T) *PgctlResult
- type PostgreSQLConfig
- type PostgreSQLContainer
- func SetupPostgreSQLContainer(ctx context.Context, t *testing.T) *PostgreSQLContainer
- func SetupPostgreSQLContainerWithVersion(ctx context.Context, t *testing.T, image string) *PostgreSQLContainer
- func SetupPostgreSQLContainerWithWalLevel(ctx context.Context, t *testing.T, walLevel string) *PostgreSQLContainer
- func (p *PostgreSQLContainer) Cleanup(ctx context.Context, t *testing.T)
- func (p *PostgreSQLContainer) CreateExtensionWithOldVersion(ctx context.Context, t *testing.T, extensionName string)
- func (p *PostgreSQLContainer) CreatePgxPool(ctx context.Context, t *testing.T) *pgxpool.Pool
- func (p *PostgreSQLContainer) CreateTestExtensions(ctx context.Context, t *testing.T)
- func (p *PostgreSQLContainer) CreateTestTable(ctx context.Context, t *testing.T)
- func (p *PostgreSQLContainer) ExecuteSQL(ctx context.Context, t *testing.T, query string, args ...interface{})
- func (p *PostgreSQLContainer) ExecuteSQLWithTimeout(ctx context.Context, t *testing.T, timeout time.Duration, query string, ...) error
- func (p *PostgreSQLContainer) InsertTestData(ctx context.Context, t *testing.T)
- func (p *PostgreSQLContainer) VerifyExtensionVersion(ctx context.Context, t *testing.T, extensionName, expectedVersion string)
- func (p *PostgreSQLContainer) WaitForReadiness(ctx context.Context, t *testing.T, timeout time.Duration)
Constants ¶
const ( // Standard test config with existing database TestConfigWithExistingDB = ` existing_db: database: existing host: localhost password: pass port: 5432 role: user ` // Invalid config for testing connection failures TestConfigWithInvalidDB = `` /* 134-byte string literal not displayed */ // Secure file permissions for config files (0600) SecureFilePerms = 0o600 )
Configuration constants to avoid repetition
Variables ¶
This section is empty.
Functions ¶
func CreateTempPgctlConfig ¶
func CreateTempPgctlConfig(t *testing.T, pgContainer *PostgreSQLContainer) string
createTempPgctlConfig creates a temporary .pgctl.yaml configuration file using the provided PostgreSQL container configuration
func CreateTempPgctlConfigForPublisherSubscriber ¶
func CreateTempPgctlConfigForPublisherSubscriber(t *testing.T, publisher, subscriber *PostgreSQLContainer) string
CreateTempPgctlConfigForPublisherSubscriber creates a configuration file for publisher-subscriber testing
func SetupPublisherSubscriberContainers ¶
func SetupPublisherSubscriberContainers(ctx context.Context, t *testing.T) (*PostgreSQLContainer, *PostgreSQLContainer)
SetupPublisherSubscriberContainers creates two PostgreSQL containers for testing logical replication Returns publisher (source) and subscriber (target) containers
Types ¶
type PgctlExecutor ¶
type PgctlExecutor struct {
BinaryPath string
WorkingDir string
Env []string
Timeout time.Duration
}
PgctlExecutor manages pgctl binary execution for integration tests
func NewPgctlExecutor ¶
func NewPgctlExecutor(t *testing.T) *PgctlExecutor
NewPgctlExecutor creates a new pgctl executor with default settings
func (*PgctlExecutor) Execute ¶
func (e *PgctlExecutor) Execute(ctx context.Context, t *testing.T, args ...string) *PgctlResult
Execute runs pgctl with the given arguments and returns the result
func (*PgctlExecutor) ExecuteWithInput ¶
func (e *PgctlExecutor) ExecuteWithInput(ctx context.Context, t *testing.T, stdin string, args ...string) *PgctlResult
ExecuteWithInput runs pgctl with the given arguments and stdin input
func (*PgctlExecutor) WithTimeout ¶
func (e *PgctlExecutor) WithTimeout(timeout time.Duration) *PgctlExecutor
WithTimeout sets a custom timeout for pgctl execution
type PgctlResult ¶
PgctlResult represents the result of executing pgctl binary
func ExecutePgctl ¶
ExecutePgctl is a convenience function to quickly execute pgctl with default settings
func ExecutePgctlWithInput ¶
func ExecutePgctlWithInput(ctx context.Context, t *testing.T, stdin string, args ...string) *PgctlResult
ExecutePgctlWithInput is a convenience function to execute pgctl with stdin input
func (*PgctlResult) AssertDurationLessThan ¶
func (r *PgctlResult) AssertDurationLessThan(t *testing.T, maxDuration time.Duration) *PgctlResult
AssertDurationLessThan asserts that execution took less than the given duration
func (*PgctlResult) AssertExitCode ¶
func (r *PgctlResult) AssertExitCode(t *testing.T, expectedCode int) *PgctlResult
AssertExitCode asserts the specific exit code
func (*PgctlResult) AssertFailure ¶
func (r *PgctlResult) AssertFailure(t *testing.T) *PgctlResult
AssertFailure asserts that pgctl failed (non-zero exit code)
func (*PgctlResult) AssertStderrContains ¶
func (r *PgctlResult) AssertStderrContains(t *testing.T, text string) *PgctlResult
AssertStderrContains asserts that stderr contains the given text
func (*PgctlResult) AssertStderrEmpty ¶
func (r *PgctlResult) AssertStderrEmpty(t *testing.T) *PgctlResult
AssertStderrEmpty asserts that stderr is empty
func (*PgctlResult) AssertStdoutContains ¶
func (r *PgctlResult) AssertStdoutContains(t *testing.T, text string) *PgctlResult
AssertStdoutContains asserts that stdout contains the given text
func (*PgctlResult) AssertStdoutContainsOrContains ¶
func (r *PgctlResult) AssertStdoutContainsOrContains(t *testing.T, text string, text2 string) *PgctlResult
AssertStdoutContainsOrContains asserts that stdout contains at least one of the given texts
func (*PgctlResult) AssertStdoutEmpty ¶
func (r *PgctlResult) AssertStdoutEmpty(t *testing.T) *PgctlResult
AssertStdoutEmpty asserts that stdout is empty
func (*PgctlResult) AssertSuccess ¶
func (r *PgctlResult) AssertSuccess(t *testing.T) *PgctlResult
AssertSuccess asserts that pgctl executed successfully (exit code 0)
type PostgreSQLConfig ¶
type PostgreSQLConfig struct {
Host string
Port int
Database string
User string
Password string
SSLMode string
}
PostgreSQLConfig holds the configuration for connecting to PostgreSQL
func (*PostgreSQLConfig) ConnectionString ¶
func (c *PostgreSQLConfig) ConnectionString() string
ConnectionString returns a formatted connection string for pgx
func (*PostgreSQLConfig) DSN ¶
func (c *PostgreSQLConfig) DSN() string
DSN returns a data source name for database/sql
func (*PostgreSQLConfig) InternalConnectionString ¶
func (c *PostgreSQLConfig) InternalConnectionString() string
InternalConnectionString returns a connection string using the container's internal hostname This is useful for subscriptions that need to connect within the container network
type PostgreSQLContainer ¶
type PostgreSQLContainer struct {
Container testcontainers.Container
Config PostgreSQLConfig
NetworkName string
ContainerName string
}
PostgreSQLContainer represents a test PostgreSQL container
func SetupPostgreSQLContainer ¶
func SetupPostgreSQLContainer(ctx context.Context, t *testing.T) *PostgreSQLContainer
SetupPostgreSQLContainer creates and starts a PostgreSQL container for testing
func SetupPostgreSQLContainerWithVersion ¶
func SetupPostgreSQLContainerWithVersion(ctx context.Context, t *testing.T, image string) *PostgreSQLContainer
SetupPostgreSQLContainerWithVersion creates and starts a PostgreSQL container with a specific version for testing
func SetupPostgreSQLContainerWithWalLevel ¶
func SetupPostgreSQLContainerWithWalLevel(ctx context.Context, t *testing.T, walLevel string) *PostgreSQLContainer
SetupPostgreSQLContainerWithWalLevel creates and starts a PostgreSQL container with specific WAL level
func (*PostgreSQLContainer) Cleanup ¶
func (p *PostgreSQLContainer) Cleanup(ctx context.Context, t *testing.T)
Cleanup terminates the PostgreSQL container
func (*PostgreSQLContainer) CreateExtensionWithOldVersion ¶
func (p *PostgreSQLContainer) CreateExtensionWithOldVersion(ctx context.Context, t *testing.T, extensionName string)
CreateExtensionWithOldVersion creates an extension and simulates it having an older version by manipulating the extension metadata (for testing purposes)
func (*PostgreSQLContainer) CreatePgxPool ¶
CreatePgxPool creates a pgx connection pool using the container configuration
func (*PostgreSQLContainer) CreateTestExtensions ¶
func (p *PostgreSQLContainer) CreateTestExtensions(ctx context.Context, t *testing.T)
CreateTestExtensions creates test extensions that can be used for update testing
func (*PostgreSQLContainer) CreateTestTable ¶
func (p *PostgreSQLContainer) CreateTestTable(ctx context.Context, t *testing.T)
CreateTestTable creates a sample table for testing purposes
func (*PostgreSQLContainer) ExecuteSQL ¶
func (p *PostgreSQLContainer) ExecuteSQL(ctx context.Context, t *testing.T, query string, args ...interface{})
ExecuteSQL executes SQL statements on the container database
func (*PostgreSQLContainer) ExecuteSQLWithTimeout ¶
func (p *PostgreSQLContainer) ExecuteSQLWithTimeout(ctx context.Context, t *testing.T, timeout time.Duration, query string, args ...interface{}) error
ExecuteSQLWithTimeout executes SQL statements on the container database with a timeout
func (*PostgreSQLContainer) InsertTestData ¶
func (p *PostgreSQLContainer) InsertTestData(ctx context.Context, t *testing.T)
InsertTestData inserts sample data into the test table
func (*PostgreSQLContainer) VerifyExtensionVersion ¶
func (p *PostgreSQLContainer) VerifyExtensionVersion(ctx context.Context, t *testing.T, extensionName, expectedVersion string)
VerifyExtensionVersion verifies that an extension has the expected installed version
func (*PostgreSQLContainer) WaitForReadiness ¶
func (p *PostgreSQLContainer) WaitForReadiness(ctx context.Context, t *testing.T, timeout time.Duration)
WaitForReadiness waits for the PostgreSQL container to be ready