-
Notifications
You must be signed in to change notification settings - Fork 22
Add support for .with_network and .with_network_aliases #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for .with_network and .with_network_aliases #84
Conversation
afac587
to
31bbef6
Compare
Previously, the container_bridge_ip and container_gateway_ip helpers always assumed the default “bridge” network. This change updates those methods (and related logic in _networking_config) to reference @network.name when present, ensuring correct IP and gateway retrieval for user-specified networks in docker_container.rb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds network support to the testcontainers-core gem by implementing with_network
and with_network_aliases
methods for Docker containers. The changes enable containers to be connected to custom networks with specific aliases.
- Introduces a new
Network
class for creating and managing Docker networks - Adds
with_network
andwith_network_aliases
methods to theDockerContainer
class - Implements network configuration in container creation options
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
core/testcontainers-core.gemspec | Adds development dependencies for base64 and mutex_m |
core/test/network_test.rb | Comprehensive test suite for network creation, lifecycle, and cleanup |
core/test/docker_container_test.rb | Tests for container network connectivity and alias functionality |
core/lib/testcontainers/network.rb | New Network class implementation with shared network management |
core/lib/testcontainers/docker_container.rb | Network integration into DockerContainer with configuration methods |
core/lib/testcontainers.rb | Adds require statement for the new network module |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
# | ||
# @param aliases [Array<String>] The aliases for the container in the network. | ||
def with_network_aliases(*aliases) | ||
self.aliases += aliases&.flatten |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aliases&.flatten
operation will fail if aliases
is nil because nil doesn't respond to flatten
. Use aliases.flatten
or handle the nil case explicitly.
self.aliases += aliases&.flatten | |
self.aliases += aliases.flatten |
Copilot uses AI. Check for mistakes.
end | ||
|
||
def _networking_config | ||
return nil unless network_name && !aliases&.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition !aliases&.empty?
will return true when aliases
is nil (since nil&.empty?
returns nil, and !nil
is true). This means networking config will be created even when there are no aliases. Use aliases&.any?
instead.
return nil unless network_name && !aliases&.empty? | |
return nil unless network_name && aliases&.any? |
Copilot uses AI. Check for mistakes.
"Binds" => @filesystem_binds | ||
}.compact | ||
}.compact, | ||
"NetworkingConfig": _networking_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using both string keys and symbol keys in the same hash is inconsistent. Use either 'NetworkingConfig'
or convert other keys to symbols for consistency.
"NetworkingConfig": _networking_config | |
"NetworkingConfig" => _networking_config |
Copilot uses AI. Check for mistakes.
script = <<~RUBY | ||
require "testcontainers" | ||
Testcontainers::Network::SHARED.create | ||
# no explicit close – rely on at_exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after the comment marker. Should be # no explicit close – rely on at_exit
.
Copilot uses AI. Check for mistakes.
Like discussed in #80 this is my Proposal in order to add
with_network
andwith_network_aliases