Documentation ¶
Index ¶
- Constants
- func BuildExternalConnectionString(ctx context.Context, container testcontainers.Container, ...) (string, error)
- func BuildInternalConnectionString(ctx context.Context, container testcontainers.Container, ...) (string, error)
- func WithPostgresContainer() container.ContainerOption
- type Options
- type PostgresOption
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func BuildExternalConnectionString ¶ added in v1.1.0
func BuildExternalConnectionString(ctx context.Context, container testcontainers.Container, opts ...PostgresOption) (string, error)
Return a PostgreSQL connection string for the given container with default options when the container is NOT in a network
Example: "postgres://postgres:postgres@localhost:5432/postgres_db?sslmode=disable"
func BuildInternalConnectionString ¶ added in v1.1.0
func BuildInternalConnectionString(ctx context.Context, container testcontainers.Container, opts ...PostgresOption) (string, error)
Return a PostgreSQL connection string for the given container with default options when the container is in a network
Example: "postgres://postgres:postgres@network_alias:5432/postgres_db?sslmode=disable"
func WithPostgresContainer ¶
func WithPostgresContainer() container.ContainerOption
Return a new container definition for a PostgreSQL container with default options
DockerImage: "postgres:16" Exposed ports: "5432" Environment variables: POSTGRES_DB: "postgres_db" POSTGRES_USER: "postgres" POSTGRES_PASSWORD: "postgres" BasePath: "/docker-entrypoint-initdb.d" WaitingForLog: "database system is ready to accept connections" StartupTimeout: "30 seconds"
Types ¶
type Options ¶
type Options struct { ExposedPort string Database string User string Pass string NetworkAlias *string }
Options is a type that represents the options for a PostgreSQL container
Default options: ExposedPort: "5432" Database: "postgres_db" User: "postgres" Pass: "postgres" Default network alias: nil
type PostgresOption ¶
type PostgresOption func(*Options)
PostgresOption is a type that represents a PostgreSQL option
func WithDatabase ¶
func WithDatabase(database string) PostgresOption
WithDatabase is a PostgresOption that sets the database of the PostgreSQL container
Default: "postgres_db"
func WithExposedPort ¶
func WithExposedPort(exposedPort string) PostgresOption
WithExposedPort is a PostgresOption that sets the exposed port of the PostgreSQL container
Default: "5432"
func WithNetwork ¶
func WithNetwork(network *network.Network) PostgresOption
WithNetwork is a PostgresOption that sets the network alias of the PostgreSQL container
Default: nil
func WithPass ¶
func WithPass(pass string) PostgresOption
WithPass is a PostgresOption that sets the password of the PostgreSQL container
Default: "postgres"
func WithUser ¶
func WithUser(user string) PostgresOption
WithUser is a PostgresOption that sets the user of the PostgreSQL container
Default: "postgres"