Class: Testcontainers::MariadbContainer
- Inherits:
-
DockerContainer
- Object
- DockerContainer
- Testcontainers::MariadbContainer
- Defined in:
- lib/testcontainers/mariadb.rb
Overview
MariadbContainer class is used to manage containers that runs a MariaDB database
Constant Summary collapse
- MARIADB_DEFAULT_PORT =
Default port used by the container
3306- MARIADB_DEFAULT_IMAGE =
Default image used by the container
"mariadb:latest"- MARIADB_DEFAULT_USERNAME =
"test"- MARIADB_DEFAULT_PASSWORD =
"test"- MARIADB_DEFAULT_ROOT_USERNAME =
"root"- MARIADB_DEFAULT_DATABASE =
"test"
Instance Attribute Summary collapse
-
#database ⇒ String
readonly
used by the container.
-
#password ⇒ String
readonly
used by the container.
-
#username ⇒ String
readonly
used by the container.
Instance Method Summary collapse
-
#database_url(protocol: "mariadb", username: nil, password: nil, database: nil, options: {}) ⇒ String
Returns the database url (e.g. mariadb://user:password@host:port/database).
-
#host ⇒ String
Returns the host used to connect to the container If the host is “localhost”, it is replaced by “127.0.0.1” since MariaDB fallbacks to a socket connection with “localhost”.
-
#initialize(image = MARIADB_DEFAULT_IMAGE, username: nil, password: nil, database: nil, port: nil, **kwargs) ⇒ MariadbContainer
constructor
Initializes a new instance of MariadbContainer.
-
#port ⇒ Integer
Returns the port used by the container.
-
#start ⇒ MariadbContainer
Starts the container.
-
#with_database(database) ⇒ MariadbContainer
Sets the database to use.
-
#with_password(password) ⇒ MariadbContainer
Sets the password to use.
-
#with_username(username) ⇒ MariadbContainer
Sets the username to use.
Constructor Details
#initialize(image = MARIADB_DEFAULT_IMAGE, username: nil, password: nil, database: nil, port: nil, **kwargs) ⇒ MariadbContainer
Initializes a new instance of MariadbContainer
33 34 35 36 37 38 39 40 |
# File 'lib/testcontainers/mariadb.rb', line 33 def initialize(image = MARIADB_DEFAULT_IMAGE, username: nil, password: nil, database: nil, port: nil, **kwargs) super(image, **kwargs) @username = username || ENV.fetch("MARIADB_USER", MARIADB_DEFAULT_USERNAME) @password = password || ENV.fetch("MARIADB_PASSWORD", MARIADB_DEFAULT_PASSWORD) @database = database || ENV.fetch("MARIADB_DATABASE", MARIADB_DEFAULT_DATABASE) @healthcheck ||= add_healthcheck() @wait_for ||= add_wait_for(:healthcheck) end |
Instance Attribute Details
#database ⇒ String (readonly)
used by the container
10 11 12 |
# File 'lib/testcontainers/mariadb.rb', line 10 def database @database end |
#password ⇒ String (readonly)
used by the container
10 11 12 |
# File 'lib/testcontainers/mariadb.rb', line 10 def password @password end |
#username ⇒ String (readonly)
used by the container
10 11 12 |
# File 'lib/testcontainers/mariadb.rb', line 10 def username @username end |
Instance Method Details
#database_url(protocol: "mariadb", username: nil, password: nil, database: nil, options: {}) ⇒ String
Returns the database url (e.g. mariadb://user:password@host:port/database)
76 77 78 79 80 81 82 83 |
# File 'lib/testcontainers/mariadb.rb', line 76 def database_url(protocol: "mariadb", username: nil, password: nil, database: nil, options: {}) database ||= @database username ||= @username password ||= @password query_string = .empty? ? "" : "?#{URI.encode_www_form(options)}" "#{protocol}://#{username}:#{password}@#{host}:#{mapped_port(port)}/#{database}#{query_string}" end |
#host ⇒ String
Returns the host used to connect to the container If the host is “localhost”, it is replaced by “127.0.0.1” since MariaDB fallbacks to a socket connection with “localhost”
56 57 58 59 |
# File 'lib/testcontainers/mariadb.rb', line 56 def host host = super (host == "localhost") ? "127.0.0.1" : host end |
#port ⇒ Integer
Returns the port used by the container
64 65 66 |
# File 'lib/testcontainers/mariadb.rb', line 64 def port MARIADB_DEFAULT_PORT end |
#start ⇒ MariadbContainer
Starts the container
45 46 47 48 49 |
# File 'lib/testcontainers/mariadb.rb', line 45 def start with_exposed_ports(port) _configure super end |
#with_database(database) ⇒ MariadbContainer
Sets the database to use
89 90 91 92 |
# File 'lib/testcontainers/mariadb.rb', line 89 def with_database(database) @database = database self end |
#with_password(password) ⇒ MariadbContainer
Sets the password to use
107 108 109 110 |
# File 'lib/testcontainers/mariadb.rb', line 107 def with_password(password) @password = password self end |
#with_username(username) ⇒ MariadbContainer
Sets the username to use
98 99 100 101 |
# File 'lib/testcontainers/mariadb.rb', line 98 def with_username(username) @username = username self end |