Class: Testcontainers::ElasticsearchContainer
- Inherits:
-
DockerContainer
- Object
- DockerContainer
- Testcontainers::ElasticsearchContainer
- Defined in:
- lib/testcontainers/elasticsearch.rb
Overview
ElasticsearchContainer class is used to manage Docker containers running Elasticsearch. It extends the generic DockerContainer class and provides Elasticsearch-specific functionality.
Constant Summary collapse
- ELASTICSEARCH_DEFAULT_HTTP_PORT =
9200
- ELASTICSEARCH_DEFAULT_TCP_PORT =
9300
- ELASTICSEARCH_DEFAULT_IMAGE =
"docker.elastic.co/elasticsearch/elasticsearch:8.7.1"
- ELASTICSEARCH_DEFAULT_USERNAME =
"elastic"
- ELASTICSEARCH_DEFAULT_PASSWORD =
"elastic"
Instance Attribute Summary collapse
-
#password ⇒ String
readonly
the Elasticsearch password.
-
#username ⇒ String
readonly
the Elasticsearch username.
Instance Method Summary collapse
-
#elasticsearch_url(protocol: nil, port: nil, username: nil, password: nil) ⇒ String
Returns the URL to access Elasticsearch.
-
#http_port ⇒ Integer
Returns the HTTP port used by the container.
-
#initialize(image = ELASTICSEARCH_DEFAULT_IMAGE, http_port: nil, tcp_port: nil, username: nil, password: nil, **kwargs) ⇒ ElasticsearchContainer
constructor
Initializes a new ElasticsearchContainer instance.
-
#start ⇒ ElasticsearchContainer
Starts the container.
-
#tcp_port ⇒ Integer
Returns the TCP (transport) port used by the container.
Constructor Details
#initialize(image = ELASTICSEARCH_DEFAULT_IMAGE, http_port: nil, tcp_port: nil, username: nil, password: nil, **kwargs) ⇒ ElasticsearchContainer
Initializes a new ElasticsearchContainer instance.
28 29 30 31 32 33 34 |
# File 'lib/testcontainers/elasticsearch.rb', line 28 def initialize(image = ELASTICSEARCH_DEFAULT_IMAGE, http_port: nil, tcp_port: nil, username: nil, password: nil, **kwargs) super(image, **kwargs) @username = username || ELASTICSEARCH_DEFAULT_USERNAME @password = password || ELASTICSEARCH_DEFAULT_PASSWORD @healthcheck ||= add_healthcheck() @wait_for ||= add_wait_for(:healthcheck) end |
Instance Attribute Details
#password ⇒ String (readonly)
the Elasticsearch password
10 11 12 |
# File 'lib/testcontainers/elasticsearch.rb', line 10 def password @password end |
#username ⇒ String (readonly)
the Elasticsearch username
10 11 12 |
# File 'lib/testcontainers/elasticsearch.rb', line 10 def username @username end |
Instance Method Details
#elasticsearch_url(protocol: nil, port: nil, username: nil, password: nil) ⇒ String
Returns the URL to access Elasticsearch
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/testcontainers/elasticsearch.rb', line 66 def elasticsearch_url(protocol: nil, port: nil, username: nil, password: nil) if protocol.nil? protocol = (get_env("xpack.security.enabled") == "true") ? "https" : "http" end username ||= @username password ||= @password port ||= http_port "#{protocol}://#{username}:#{password}@#{host}:#{mapped_port(port)}" end |
#http_port ⇒ Integer
Returns the HTTP port used by the container
48 49 50 |
# File 'lib/testcontainers/elasticsearch.rb', line 48 def http_port ELASTICSEARCH_DEFAULT_HTTP_PORT end |
#start ⇒ ElasticsearchContainer
Starts the container
39 40 41 42 43 |
# File 'lib/testcontainers/elasticsearch.rb', line 39 def start with_exposed_ports(http_port, tcp_port) _configure super end |
#tcp_port ⇒ Integer
Returns the TCP (transport) port used by the container
55 56 57 |
# File 'lib/testcontainers/elasticsearch.rb', line 55 def tcp_port ELASTICSEARCH_DEFAULT_TCP_PORT end |