feat: add getMappedPort(int, InternetProtocol) overload to ContainerState#11780
Open
suryateja-g13 wants to merge 1 commit into
Open
feat: add getMappedPort(int, InternetProtocol) overload to ContainerState#11780suryateja-g13 wants to merge 1 commit into
suryateja-g13 wants to merge 1 commit into
Conversation
…tate The existing getMappedPort(int) always looks up TCP bindings. UDP-exposed ports cannot be queried without manually traversing getContainerInfo(). Add an overload that accepts an InternetProtocol argument so callers can look up both TCP and UDP mapped ports through the same typed API. The no-arg overload is reimplemented to delegate to the new method with InternetProtocol.TCP so the two code paths share the same logic. Closes testcontainers#554 Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #554
The existing
getMappedPort(int)always performs a TCP lookup. There is no typed API to retrieve the mapped port for a UDP-exposed container port — callers must walk the fullgetContainerInfo()chain manually, as noted in the original issue.Changes
ContainerStategetMappedPort(int originalPort, InternetProtocol protocol)— looks up the mapped host port for anyInternetProtocol(TCP or UDP).getMappedPort(int)to delegate to the new overload withInternetProtocol.TCP, so both paths share the same logic."Requested port (53/udp) is not mapped").Tests
Added three unit tests to
ContainerStateTest(no Docker required, Mockito-only):getMappedPortWithTcpProtocolReturnsMappedPort— verifies TCP lookup returns the correct mapped port via both the no-arg and protocol overloads.getMappedPortWithUdpProtocolReturnsMappedPort— verifies UDP port lookup returns the correct mapped port.getMappedPortThrowsWhenPortNotMapped— verifiesIllegalArgumentExceptionis thrown for an unmapped UDP port, with the port/protocol in the message.All 9 tests in
ContainerStateTestpass.