testcontainers-mysql 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +3 -3
- data/README.md +22 -4
- data/lib/testcontainers/mysql/version.rb +1 -1
- data/lib/testcontainers/mysql.rb +15 -4
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 321c7acc969cd09e9abb47ad22be5146f1ced8f11024778b29efc2e06a9a74a6
|
4
|
+
data.tar.gz: d86b26751a25a110d19f35df5359773fcb09bcfbf9dd97782cd99cf38db5ba8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 246f7ccb0eb529035ff205becfb14ad1c72103239dc2b7349a6ac51b33c45709d0f2f89e3402e99b1cd54217049755340184aad1cb71608910a2b478db3d6a42
|
7
|
+
data.tar.gz: 9e4872a00506ff9518ee49a9bf8272eedd2c645dfe5f8bea7402c1c78c2f777dacdc7096dde92faae2578a06886f591878f7821f690634f527cc320d0289bdd9
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../core
|
3
3
|
specs:
|
4
|
-
testcontainers-core (0.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.
|
11
|
-
testcontainers-core (~> 0.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
|
-
###
|
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/
|
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/
|
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).
|
data/lib/testcontainers/mysql.rb
CHANGED
@@ -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 :
|
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(
|
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.
|
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-
|
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.
|
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.
|
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/
|
113
|
+
homepage: https://github.com/testcontainers/testcontainers-ruby
|
114
114
|
licenses:
|
115
115
|
- MIT
|
116
116
|
metadata:
|
117
|
-
homepage_uri: https://github.com/
|
118
|
-
source_code_uri: https://github.com/
|
119
|
-
changelog_uri: https://github.com/
|
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:
|