Class: Bidi2pdf::TestHelpers::Testcontainers::ChromedriverContainer
- Inherits:
-
Testcontainers::DockerContainer
- Object
- Testcontainers::DockerContainer
- Bidi2pdf::TestHelpers::Testcontainers::ChromedriverContainer
- Defined in:
- lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb
Constant Summary collapse
- DEFAULT_CHROMEDRIVER_PORT =
3000
- DEFAULT_IMAGE =
"dieters877565/chromedriver"
Instance Attribute Summary collapse
-
#build_dir ⇒ Object
readonly
Returns the value of attribute build_dir.
-
#docker_file ⇒ Object
readonly
Returns the value of attribute docker_file.
Instance Method Summary collapse
-
#build_local_image ⇒ Object
rubocop: disable Metrics/AbcSize.
-
#initialize(image = DEFAULT_IMAGE, **options) ⇒ ChromedriverContainer
constructor
A new instance of ChromedriverContainer.
- #port ⇒ Object
-
#session_url(protocol: "http") ⇒ Object
rubocop: enable Metrics/AbcSize.
- #start ⇒ Object
-
#start_local_image ⇒ Object
rubocop: disable Metrics/AbcSize.
Constructor Details
#initialize(image = DEFAULT_IMAGE, **options) ⇒ ChromedriverContainer
Returns a new instance of ChromedriverContainer.
12 13 14 15 16 17 18 19 |
# File 'lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb', line 12 def initialize(image = DEFAULT_IMAGE, **) @docker_file = .delete(:docker_file) || "Dockerfile" @build_dir = .delete(:build_dir) || [:working_dir] super @wait_for ||= add_wait_for(:logs, /ChromeDriver was started successfully on port/) end |
Instance Attribute Details
#build_dir ⇒ Object (readonly)
Returns the value of attribute build_dir.
10 11 12 |
# File 'lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb', line 10 def build_dir @build_dir end |
#docker_file ⇒ Object (readonly)
Returns the value of attribute docker_file.
10 11 12 |
# File 'lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb', line 10 def docker_file @docker_file end |
Instance Method Details
#build_local_image ⇒ Object
rubocop: disable Metrics/AbcSize
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb', line 31 def build_local_image old_timeout = Docker.[:read_timeout] Docker.[:read_timeout] = 60 * 10 Docker::Image.build_from_dir(build_dir, { "t" => image, "dockerfile" => docker_file }) do |lines| lines.split("\n").each do |line| next unless (log = JSON.parse(line)) && log.key?("stream") next unless log["stream"] && !(trimmed_stream = log["stream"].strip).empty? = Time.now.strftime("[%Y-%m-%dT%H:%M:%S.%6N]") $stdout.write "#{} #{trimmed_stream}\n" end end Docker.[:read_timeout] = old_timeout end |
#port ⇒ Object
26 27 28 |
# File 'lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb', line 26 def port DEFAULT_CHROMEDRIVER_PORT end |
#session_url(protocol: "http") ⇒ Object
rubocop: enable Metrics/AbcSize
75 76 77 |
# File 'lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb', line 75 def session_url(protocol: "http") "#{protocol}://#{host}:#{mapped_port(port)}/session" end |
#start ⇒ Object
21 22 23 24 |
# File 'lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb', line 21 def start with_exposed_ports(port) super end |
#start_local_image ⇒ Object
rubocop: disable Metrics/AbcSize
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb', line 51 def start_local_image build_local_image with_exposed_ports(port) @_container ||= Docker::Container.create() @_container.start @_id = @_container.id json = @_container.json @name = json["Name"] @_created_at = json["Created"] @wait_for&.call(self) self rescue Docker::Error::NotFoundError => e raise Testcontainers::NotFoundError, e. rescue Excon::Error::Socket => e raise Testcontainers::ConnectionError, e. end |