Skip to content
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

Fix case-sensitivity bug for port numbers in command #524

Merged
merged 6 commits into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

### Fixed
- Fixed problem with case-sensitivity when checking internal port. ([\#524](https://github.com/testcontainers/testcontainers-java/pull/524))

### Changed
- Added `getDatabaseName` method to JdbcDatabaseContainer, MySQLContainer, PostgreSQLContainer ([\#473](https://github.com/testcontainers/testcontainers-java/issues/473))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Boolean call() {

private void tryPort(Integer internalPort) {
String[][] commands = {
{"/bin/sh", "-c", format("cat /proc/net/tcp | awk '{print $2}' | grep :%x && echo %s", internalPort, SUCCESS_MARKER)},
{"/bin/sh", "-c", format("cat /proc/net/tcp | awk '{print $2}' | grep -i :%x && echo %s", internalPort, SUCCESS_MARKER)},
{"/bin/sh", "-c", format("nc -vz -w 1 localhost %d && echo %s", internalPort, SUCCESS_MARKER)},
{"/bin/bash", "-c", format("</dev/tcp/localhost/%d && echo %s", internalPort, SUCCESS_MARKER)}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
import com.google.common.collect.ImmutableSet;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please fix the indentation in this file?
Also, IMO we can just use nc for this test to avoid creating a config for nginx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, sorry, will fix the indentation.

I had a problem with netcat and the infinispan container before, it's not installed. I could imagine other containers not supporting it, too. In fact I thought this was the reason for the /proc/net/tcp solution here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok, I see 👍

import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;

import static org.rnorth.visibleassertions.VisibleAssertions.assertThrows;
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;

public class InternalCommandPortListeningCheckTest {

// Linking a custom configuration into the container so that nginx is listening on port 8080. This is necessary to proof
// that the command formatting uses the correct casing for hexadecimal numberd (i.e. 1F90 and not 1f90).
@Rule
public GenericContainer nginx = new GenericContainer<>("nginx:1.9.4");
public GenericContainer nginx = new GenericContainer<>("nginx:1.9.4")
.withClasspathResourceMapping("nginx_on_8080.conf", "/etc/nginx/conf.d/default.conf", BindMode.READ_ONLY);

@Test
public void singleListening() {
final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck(nginx, ImmutableSet.of(80));
final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck(nginx, ImmutableSet.of(8080));

final Boolean result = check.call();

Expand All @@ -24,7 +28,7 @@ public void singleListening() {

@Test
public void nonListening() {
final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck(nginx, ImmutableSet.of(80, 1234));
final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck(nginx, ImmutableSet.of(8080, 1234));

assertThrows("InternalCommandPortListeningCheck detects a non-listening port among many",
IllegalStateException.class,
Expand Down
5 changes: 5 additions & 0 deletions core/src/test/resources/nginx_on_8080.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This configuration makes Nginx listen on port port 8080

server {
listen 8080;
}