testcontainers-rabbitmq 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5d97a9dd11ccfa2cdf0306fee0ce355a1ae6ae7d9cc242c62e0f450734d3afd1
4
+ data.tar.gz: eb2f0e776019538d07c04e2bc5b434fecb7fb387868b23040bce4d27e13ca674
5
+ SHA512:
6
+ metadata.gz: b1ee3ea2117c31d37ce6ea6cb52924b9614c97577166442b69eb3c0a59b766bd5f4b35bf008fa38b64e195f45f6c91bcf93db46ef01370ac27ebb3df210f6fa1
7
+ data.tar.gz: c127eb5be4b1f6ee4f758ef2476e7b820185e93f7f23b6f7f88010de2caf594304530d3456802a573f8ab22bd4fda96226b9c183fc2ec8c444936b875a567e92
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [Unreleased]
2
+
3
+ ### Added
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in testcontainers-rabbitmq.gemspec
6
+ gemspec
7
+
8
+ # Use the latest version of testcontainers-core from the local path
9
+ gem "testcontainers-core", path: "../core"
data/Gemfile.lock ADDED
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: ../core
3
+ specs:
4
+ testcontainers-core (0.1.3)
5
+ docker-api (~> 2.2)
6
+
7
+ PATH
8
+ remote: .
9
+ specs:
10
+ testcontainers-rabbitmq (0.1.0)
11
+ testcontainers-core (~> 0.1.3)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ amq-protocol (2.3.2)
17
+ ast (2.4.2)
18
+ bunny (2.20.3)
19
+ amq-protocol (~> 2.3, >= 2.3.1)
20
+ sorted_set (~> 1, >= 1.0.2)
21
+ docker-api (2.2.0)
22
+ excon (>= 0.47.0)
23
+ multi_json
24
+ excon (0.99.0)
25
+ json (2.6.3)
26
+ language_server-protocol (3.17.0.3)
27
+ lint_roller (1.0.0)
28
+ minitest (5.18.0)
29
+ minitest-hooks (1.5.0)
30
+ minitest (> 5.3)
31
+ multi_json (1.15.0)
32
+ parallel (1.23.0)
33
+ parser (3.2.2.1)
34
+ ast (~> 2.4.1)
35
+ rainbow (3.1.1)
36
+ rake (13.0.6)
37
+ rbtree (0.4.6)
38
+ regexp_parser (2.8.0)
39
+ rexml (3.2.5)
40
+ rubocop (1.50.2)
41
+ json (~> 2.3)
42
+ parallel (~> 1.10)
43
+ parser (>= 3.2.0.0)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ regexp_parser (>= 1.8, < 3.0)
46
+ rexml (>= 3.2.5, < 4.0)
47
+ rubocop-ast (>= 1.28.0, < 2.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 2.4.0, < 3.0)
50
+ rubocop-ast (1.28.1)
51
+ parser (>= 3.2.1.0)
52
+ rubocop-performance (1.16.0)
53
+ rubocop (>= 1.7.0, < 2.0)
54
+ rubocop-ast (>= 0.4.0)
55
+ ruby-progressbar (1.13.0)
56
+ set (1.0.3)
57
+ sorted_set (1.0.3)
58
+ rbtree
59
+ set (~> 1.0)
60
+ standard (1.28.4)
61
+ language_server-protocol (~> 3.17.0.2)
62
+ lint_roller (~> 1.0)
63
+ rubocop (~> 1.50.2)
64
+ standard-custom (~> 1.0.0)
65
+ standard-performance (~> 1.0.1)
66
+ standard-custom (1.0.0)
67
+ lint_roller (~> 1.0)
68
+ standard-performance (1.0.1)
69
+ lint_roller (~> 1.0)
70
+ rubocop-performance (~> 1.16.0)
71
+ unicode-display_width (2.4.2)
72
+
73
+ PLATFORMS
74
+ arm64-darwin-21
75
+ x86_64-darwin-22
76
+
77
+ DEPENDENCIES
78
+ bunny (~> 2.19)
79
+ minitest (~> 5.0)
80
+ minitest-hooks (~> 1.5)
81
+ rake (~> 13.0)
82
+ standard (~> 1.3)
83
+ testcontainers-core!
84
+ testcontainers-rabbitmq!
85
+
86
+ BUNDLED WITH
87
+ 2.4.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Guillermo Iguaran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # Testcontainers module for RabbitMQ
2
+
3
+ ## Installation
4
+
5
+ Add the library to the test section in your application's Gemfile:
6
+
7
+ ```ruby
8
+ group :test do
9
+ gem 'testcontainers-rabbitmq'
10
+ end
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install testcontainers-rabbitmq
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ To use the library, you first need to require it:
28
+
29
+ ```ruby
30
+ require "testcontainers/rabbitmq"
31
+ ```
32
+
33
+ ### Creating a RabbitMQ container
34
+
35
+ Create a new instance of the `Testcontainers::RabbitmqContainer` class:
36
+
37
+ ```ruby
38
+ container = Testcontainers::RabbitmqContainer.new
39
+ ```
40
+
41
+ This creates a new container with the default RabbitMQ image, user, password, and vhost. You can customize these by passing arguments to the constructor:
42
+
43
+ ```ruby
44
+ container = Testcontainers::RabbitmqContainer.new("rabbitmq:latest", username: "custom_user", password: "custom_pass", vhost: "custom_vhost")
45
+ ```
46
+
47
+ ### Starting and stopping the container
48
+
49
+ Start the container:
50
+
51
+ ```ruby
52
+ container.start
53
+ ```
54
+
55
+ Stop the container when you're done:
56
+
57
+ ```ruby
58
+ container.stop
59
+ ```
60
+
61
+ ### Connecting to the RabbitMQ container
62
+
63
+ Once the container is running, you can obtain the connection details using the following methods:
64
+
65
+ ```ruby
66
+ host = container.host
67
+ port = container.first_mapped_port
68
+ ```
69
+
70
+ Or, you can generate a full RabbitMQ URL:
71
+
72
+ ```ruby
73
+ broker_url = container.rabbitmq_url
74
+ ```
75
+
76
+ ### Customizing the container
77
+
78
+ ```ruby
79
+ container.with_vhost("custom_vhost")
80
+ container.with_username("custom_user")
81
+ container.with_password("custom_pass")
82
+ ```
83
+
84
+ ### Example
85
+
86
+ There are complete examples of how to use testcontainers-rabbitmq to create containers, connects to it, publish and consume simple message:
87
+
88
+ ```ruby
89
+ require "testcontainers/rabbitmq"
90
+ require "bunny"
91
+
92
+ container = Testcontainers::RabbitmqContainer.new
93
+ container.start
94
+
95
+ connection = Bunny.new(container.rabbitmq_url)
96
+ connection.start
97
+
98
+ channel = connection.create_channel
99
+ queue = channel.queue('hello')
100
+ channel.default_exchange.publish('Hello World!', routing_key: queue.name)
101
+
102
+ connection.close
103
+ ```
104
+
105
+ The previous example creates a RabbitMQ container, connects to it using `bunny` gem, then publish a message to a queue named `hello`
106
+
107
+ ```ruby
108
+ require "testcontainers/rabbitmq"
109
+ require "bunny"
110
+
111
+ container = Testcontainers::RabbitmqContainer.new
112
+ container.start
113
+
114
+ connection = Bunny.new(container.rabbitmq_url)
115
+ connection.start
116
+
117
+ channel = connection.create_channel
118
+ queue = channel.queue('hello')
119
+
120
+ queue.subscribe(block: true) do |_delivery_info, _properties, body|
121
+ puts " [x] Received #{body}"
122
+ end
123
+
124
+ connection.close
125
+ ```
126
+
127
+ The previous example creates a RabbitMQ container, connects to it using `bunny` gem, then reads messages from a queue named `hello`
128
+
129
+ ## Contributing
130
+
131
+ 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).
132
+
133
+ ## License
134
+
135
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
+
137
+ ## Code of Conduct
138
+
139
+ 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/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Testcontainers
4
+ module Rabbitmq
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,150 @@
1
+ require_relative "rabbitmq/version"
2
+ require "testcontainers"
3
+ require "uri"
4
+
5
+ module Testcontainers
6
+ # RabbitmqContainer class is used to manage containers that runs a RabbitMQ message broker
7
+ #
8
+ # @attr_reader [String] username used by the container
9
+ # @attr_reader [String] password used by the container
10
+ # @attr_reader [String] database used by the container
11
+ class RabbitmqContainer < ::Testcontainers::DockerContainer
12
+ # Default ports used by the container
13
+ RABBITMQ_QUEUE_DEFAULT_PORT = 5672
14
+ RABBITMQ_MGMT_UI_DEFAULT_PORT = 15672
15
+
16
+ # Default image used by the container
17
+ # To have the management plugin enabled, use the image with the tag "management"
18
+ RABBITMQ_DEFAULT_IMAGE = "rabbitmq:latest"
19
+
20
+ # Default credentials used by the container
21
+ RABBITMQ_DEFAULT_USER = "rabbitmq"
22
+ RABBITMQ_DEFAULT_PASS = "rabbitmq"
23
+
24
+ # Default vhost used by the container
25
+ RABBITMQ_DEFAULT_VHOST = "/"
26
+
27
+ attr_reader :username, :password, :vhost
28
+
29
+ # Initializes a new instance of RabbitMQContainer
30
+ #
31
+ # @param image [String] the image to use
32
+ # @param username [String] the username to use
33
+ # @param password [String] the password to use
34
+ # @param port [String] the port to use
35
+ # @param kwargs [Hash] the options to pass to the container. See {DockerContainer#initialize}
36
+ # @return [RabbitmqContainer] a new instance of RabbitmqContainer
37
+ def initialize(image = RABBITMQ_DEFAULT_IMAGE, username: nil, password: nil, vhost: nil, **kwargs)
38
+ super(image, **kwargs)
39
+ @username = username || ENV.fetch("RABBITMQ_USER", RABBITMQ_DEFAULT_USER)
40
+ @password = password || ENV.fetch("RABBITMQ_PASSWORD", RABBITMQ_DEFAULT_PASS)
41
+ @vhost = vhost || ENV.fetch("RABBITMQ_VHOST", RABBITMQ_DEFAULT_VHOST)
42
+ @healthcheck ||= add_healthcheck(_default_healthcheck_options)
43
+ @wait_for ||= add_wait_for(:healthcheck)
44
+ end
45
+
46
+ # Starts the container
47
+ #
48
+ # @return [RabbitmqContainer] self
49
+ def start
50
+ with_exposed_ports([port, management_ui_port])
51
+ _configure
52
+ super
53
+ end
54
+
55
+ # Returns the port used to connect to the container queue
56
+ #
57
+ # @return [Integer] the port used by the container
58
+ def port
59
+ RABBITMQ_QUEUE_DEFAULT_PORT
60
+ end
61
+
62
+ # Returns the port used to connect to the container management UI
63
+ # This is available only if an image with the management plugin enabled is used
64
+ #
65
+ # @return [Integer] the port used by the container
66
+ def management_ui_port
67
+ RABBITMQ_MGMT_UI_DEFAULT_PORT
68
+ end
69
+
70
+ # Returns the rabbitmq connection url (e.g. amqp://user:password@host:port/vhost)
71
+ #
72
+ # @param protocol [String] the protocol to use in the string (default: "mysql")
73
+ # @param database [String] the database to use in the string (default: @database)
74
+ # @param options [Hash] the options to use in the query string (default: {})
75
+ # @return [String] the rabbitmq url
76
+ # @raise [ConnectionError] If the connection to the Docker daemon fails.
77
+ # @raise [ContainerNotStartedError] If the container has not been started.
78
+ def rabbitmq_url(protocol: "amqp://", username: nil, password: nil, vhost: nil)
79
+ username ||= @username
80
+ password ||= @password
81
+ vhost ||= @vhost
82
+ vhost = "/#{vhost}" unless vhost.start_with?("/")
83
+ vhost = "" if vhost == "/"
84
+
85
+ # amqp://user:pass@host:10000/vhost
86
+ "#{protocol}#{username}:#{password}@#{host}:#{mapped_port(port)}#{vhost}"
87
+ end
88
+
89
+ alias_method :connection_url, :rabbitmq_url
90
+
91
+ # Returns the rabbitmq management UI url (e.g. http://user:password@host:port)
92
+ #
93
+ # @param protocol [String] the protocol to use in the string (default: "http")
94
+ # @return [String] the url for the management UI. Returns nil if the management UI is not available.
95
+ # @raise [ConnectionError] If the connection to the Docker daemon fails.
96
+ # @raise [ContainerNotStartedError] If the container has not been started.
97
+ def management_ui_url(protocol: "http")
98
+ port = mapped_port(management_ui_port)
99
+ port.nil? ? nil : "#{protocol}://#{host}:#{port}"
100
+ end
101
+
102
+ # Sets the vhost to use
103
+ #
104
+ # @param vhost [String] the vhost to use
105
+ # @return [RabbitmqContainer] self
106
+ def with_vhost(vhost)
107
+ @vhost = vhost
108
+ self
109
+ end
110
+
111
+ # Sets the username to use
112
+ #
113
+ # @param username [String] the username to use
114
+ # @return [RabbitmqContainer] self
115
+ def with_username(username)
116
+ @username = username
117
+ self
118
+ end
119
+
120
+ # Sets the password to use
121
+ #
122
+ # @param password [String] the password to use
123
+ # @return [RabbitmqContainer] self
124
+ def with_password(password)
125
+ @password = password
126
+ self
127
+ end
128
+
129
+ # Returns the container's first mapped port (the one used by the queue)
130
+ #
131
+ # @return [Integer] The container's first mapped port.
132
+ # @raise [ConnectionError] If the connection to the Docker daemon fails.
133
+ def first_mapped_port
134
+ raise ContainerNotStartedError unless @_container
135
+ mapped_port(port)
136
+ end
137
+
138
+ private
139
+
140
+ def _configure
141
+ add_env("RABBITMQ_DEFAULT_USER", @username)
142
+ add_env("RABBITMQ_DEFAULT_PASS", @password)
143
+ add_env("RABBITMQ_DEFAULT_VHOST", @vhost) if @vhost
144
+ end
145
+
146
+ def _default_healthcheck_options
147
+ {test: %w[rabbitmqctl node_health_check], interval: 10, timeout: 10, retries: 5}
148
+ end
149
+ end
150
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testcontainers-rabbitmq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Piza
8
+ - Guillermo Iguaran
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2023-06-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: testcontainers-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.1.3
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.3
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '13.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '13.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '5.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest-hooks
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.5'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.5'
70
+ - !ruby/object:Gem::Dependency
71
+ name: standard
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.3'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.3'
84
+ - !ruby/object:Gem::Dependency
85
+ name: bunny
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.19'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '2.19'
98
+ description: Testcontainers makes it easy to create and clean up container-based dependencies
99
+ for automated tests.
100
+ email:
101
+ - pedro920224@gmail.com
102
+ - guilleiguaran@gmail.com
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - CHANGELOG.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/testcontainers/rabbitmq.rb
114
+ - lib/testcontainers/rabbitmq/version.rb
115
+ homepage: https://github.com/testcontainers/testcontainers-ruby
116
+ licenses:
117
+ - MIT
118
+ metadata:
119
+ homepage_uri: https://github.com/testcontainers/testcontainers-ruby/blob/main/rabbitmq
120
+ source_code_uri: https://github.com/testcontainers/testcontainers-ruby/blob/main/rabbitmq
121
+ changelog_uri: https://github.com/testcontainers/testcontainers-ruby/blob/main/rabbitmq/CHANGELOG.md
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.6.0
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.4.1
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: 'Testcontainers for Ruby: Rabbitmq module'
141
+ test_files: []