testcontainers-mysql 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6cb938c40f21035fe967d0ac06a0a09dc6d3f976d94e51cadd5363721ad11bb
4
- data.tar.gz: 236c54c790761d62ad9c87b427ac60be26ed5cb99b60d73e554096d7b7f302eb
3
+ metadata.gz: 321c7acc969cd09e9abb47ad22be5146f1ced8f11024778b29efc2e06a9a74a6
4
+ data.tar.gz: d86b26751a25a110d19f35df5359773fcb09bcfbf9dd97782cd99cf38db5ba8e
5
5
  SHA512:
6
- metadata.gz: e51a9a3e5e4333eef7f9c092f6092f787eabb154300340ecf1b0b98a2e12fe97b62daa33b399bd9b5fab91fa0d2cddb7526ac14bf05af144b0933b99dee03fc9
7
- data.tar.gz: 306ce8bb8cf32455ec2fb0bc50abfbf25aaff041b356349ed328270e2860008185d0c710e78148312e328b41d38185b7ad57e3bc63e97518e11cc98385a7f006
6
+ metadata.gz: 246f7ccb0eb529035ff205becfb14ad1c72103239dc2b7349a6ac51b33c45709d0f2f89e3402e99b1cd54217049755340184aad1cb71608910a2b478db3d6a42
7
+ data.tar.gz: 9e4872a00506ff9518ee49a9bf8272eedd2c645dfe5f8bea7402c1c78c2f777dacdc7096dde92faae2578a06886f591878f7821f690634f527cc320d0289bdd9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [0.1.1] - 2023-06-10
2
+
3
+ ### Added
4
+
5
+ - Add healthcheck support on start
6
+
7
+ ### Fixed
8
+
9
+ - Remove support for custom ports, it is not supported by underlying
10
+ images.
11
+
1
12
  ## [0.1.0] - 2023-05-13
2
13
 
3
14
  ### Added
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: ../core
3
3
  specs:
4
- testcontainers-core (0.1.1)
4
+ testcontainers-core (0.1.3)
5
5
  docker-api (~> 2.2)
6
6
 
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- testcontainers-mysql (0.1.0)
11
- testcontainers-core (~> 0.1.1)
10
+ testcontainers-mysql (0.1.1)
11
+ testcontainers-core (~> 0.1.3)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -79,7 +79,6 @@ port = container.first_mapped_port
79
79
  ```
80
80
 
81
81
 
82
-
83
82
  Or, you can generate a full database URL:
84
83
 
85
84
  ```ruby
@@ -122,11 +121,30 @@ container.stop
122
121
 
123
122
  This example creates a MySQL container, connects to it using the `mysql2` gem, runs a simple `SELECT 1` query, and then stops the container.
124
123
 
125
- ### Example with RSpec
124
+ ### Using with RSpec
125
+
126
+ You can manage the container in the `before(:suite)` / `after(:suite)` blocks in your `spec_helper.rb`:
127
+
128
+ ```ruby
129
+ RSpec.configure do |config|
130
+ # This helps us to have access to the `RSpec.configuration.mysql_container` without using global variables.
131
+ config.add_setting :mysql, default: nil
132
+
133
+ config.before(:suite) do
134
+ config.mysql_container = Testcontainers::MysqlContainer.new.start
135
+ ENV["DATABASE_URL"] = config.mysql_container.database_url(protocol: "mysql2") # or you can expose it to a fixed port and use database.yml for configuration
136
+ end
137
+
138
+ config.after(:suite) do
139
+ config.mysql_container&.stop
140
+ config.mysql_container&.remove
141
+ end
142
+ end
143
+ ```
126
144
 
127
145
  ## Contributing
128
146
 
129
- Bug reports and pull requests are welcome on GitHub at https://github.com/guilleiguaran/testcontainers. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/guilleiguaran/testcontainers/blob/main/CODE_OF_CONDUCT.md).
147
+ Bug reports and pull requests are welcome on GitHub at https://github.com/testcontainers/testcontainers-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/testcontainers/testcontainers-ruby/blob/main/CODE_OF_CONDUCT.md).
130
148
 
131
149
  ## License
132
150
 
@@ -134,4 +152,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
134
152
 
135
153
  ## Code of Conduct
136
154
 
137
- Everyone interacting in the Testcontainers project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/guilleiguaran/testcontainers/blob/main/CODE_OF_CONDUCT.md).
155
+ Everyone interacting in the Testcontainers project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/testcontainers/testcontainers-ruby/blob/main/CODE_OF_CONDUCT.md).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Testcontainers
4
4
  module Mysql
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -5,7 +5,6 @@ require "uri"
5
5
  module Testcontainers
6
6
  # MysqlContainer class is used to manage containers that runs a MySQL database
7
7
  #
8
- # @attr_reader [String] port used by the container
9
8
  # @attr_reader [String] username used by the container
10
9
  # @attr_reader [String] password used by the container
11
10
  # @attr_reader [String] database used by the container
@@ -21,7 +20,7 @@ module Testcontainers
21
20
  MYSQL_DEFAULT_ROOT_USERNAME = "root"
22
21
  MYSQL_DEFAULT_DATABASE = "test"
23
22
 
24
- attr_reader :port, :username, :password, :database
23
+ attr_reader :username, :password, :database
25
24
 
26
25
  # Initializes a new instance of MysqlContainer
27
26
  #
@@ -34,17 +33,18 @@ module Testcontainers
34
33
  # @return [MysqlContainer] a new instance of MysqlContainer
35
34
  def initialize(image = MYSQL_DEFAULT_IMAGE, username: nil, password: nil, database: nil, port: nil, **kwargs)
36
35
  super(image, **kwargs)
37
- @port = port || ENV.fetch("MYSQL_PORT", MYSQL_DEFAULT_PORT)
38
36
  @username = username || ENV.fetch("MYSQL_USER", MYSQL_DEFAULT_USERNAME)
39
37
  @password = password || ENV.fetch("MYSQL_PASSWORD", MYSQL_DEFAULT_PASSWORD)
40
38
  @database = database || ENV.fetch("MYSQL_DATABASE", MYSQL_DEFAULT_DATABASE)
39
+ @healthcheck ||= add_healthcheck(_default_healthcheck_options)
40
+ @wait_for ||= add_wait_for(:healthcheck)
41
41
  end
42
42
 
43
43
  # Starts the container
44
44
  #
45
45
  # @return [MysqlContainer] self
46
46
  def start
47
- with_exposed_ports(@port)
47
+ with_exposed_ports(port)
48
48
  _configure
49
49
  super
50
50
  end
@@ -59,6 +59,13 @@ module Testcontainers
59
59
  (host == "localhost") ? "127.0.0.1" : host
60
60
  end
61
61
 
62
+ # Returns the port used by the container
63
+ #
64
+ # @return [Integer] the port used by the container
65
+ def port
66
+ MYSQL_DEFAULT_PORT
67
+ end
68
+
62
69
  # Returns the database url (e.g. mysql://user:password@host:port/database)
63
70
  #
64
71
  # @param protocol [String] the protocol to use in the string (default: "mysql")
@@ -118,5 +125,9 @@ module Testcontainers
118
125
  raise ContainerLaunchException, "Password is required for non-root users"
119
126
  end
120
127
  end
128
+
129
+ def _default_healthcheck_options
130
+ {test: ["/usr/bin/mysql", "--protocol=TCP", "--port=#{port}", "--user=#{username}", "--password=#{password}", database, "--silent", "--execute=SELECT 1;"], interval: 1, timeout: 5, retries: 5}
131
+ end
121
132
  end
122
133
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testcontainers-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Iguaran
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-13 00:00:00.000000000 Z
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: testcontainers-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: 0.1.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.2
26
+ version: 0.1.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -110,13 +110,13 @@ files:
110
110
  - Rakefile
111
111
  - lib/testcontainers/mysql.rb
112
112
  - lib/testcontainers/mysql/version.rb
113
- homepage: https://github.com/guilleiguaran/testcontainers-ruby
113
+ homepage: https://github.com/testcontainers/testcontainers-ruby
114
114
  licenses:
115
115
  - MIT
116
116
  metadata:
117
- homepage_uri: https://github.com/guilleiguaran/testcontainers-ruby/blob/main/mysql
118
- source_code_uri: https://github.com/guilleiguaran/testcontainers-ruby/blob/main/mysql
119
- changelog_uri: https://github.com/guilleiguaran/testcontainers-ruby/blob/main/mysql/CHANGELOG.md
117
+ homepage_uri: https://github.com/testcontainers/testcontainers-ruby/blob/main/mysql
118
+ source_code_uri: https://github.com/testcontainers/testcontainers-ruby/blob/main/mysql
119
+ changelog_uri: https://github.com/testcontainers/testcontainers-ruby/blob/main/mysql/CHANGELOG.md
120
120
  post_install_message:
121
121
  rdoc_options: []
122
122
  require_paths: