class

Testcontainers::PostgresContainer

Inherits Testcontainers::DockerContainer < Reference < Object

PostgresContainer provides a pre-configured container for PostgreSQL.

Example:

container = Testcontainers::PostgresContainer.new
container.start

url = container.database_url
# => "postgres://test:test@localhost:32768/test"

container.stop
container.remove

Constants

POSTGRES_DEFAULT_DATABASE = "test"
POSTGRES_DEFAULT_IMAGE = "postgres:latest"
POSTGRES_DEFAULT_PASSWORD = "test"
POSTGRES_DEFAULT_PORT = 5432
POSTGRES_DEFAULT_USERNAME = "test"

Constructors

new(image : String = POSTGRES_DEFAULT_IMAGE, username : String = ENV.fetch("POSTGRES_USER", POSTGRES_DEFAULT_USERNAME), password : String = ENV.fetch("POSTGRES_PASSWORD", POSTGRES_DEFAULT_PASSWORD), database : String = ENV.fetch("POSTGRES_DATABASE", POSTGRES_DEFAULT_DATABASE))
Source

Instance methods

database
Source
database_url(protocol : String = "postgres", username : String | Nil = nil, password : String | Nil = nil, database : String | Nil = nil, options : Hash(String, String) = Hash(String, String).new) : String

Returns the database URL.

Example: "postgres://user:password@localhost:5432/dbname"

Source
password
Source
port

Returns the default port.

Source
start

Starts the container.

Source
username
Source
with_database(database : String) : self

Sets the database name.

Source
with_password(password : String) : self

Sets the password.

Source
with_username(username : String) : self

Sets the username.

Source