Skip to content

Commit

Permalink
Update integration tests to use host.testcontainers.internal
Browse files Browse the repository at this point in the history
Motivation
While I was running the integration test, I found out that `host.docker.internal` doesn't work correctly on Linux. (It worked on Mac and Windows.)
`host.docker.internal` is used for the container to access the host but the DNS resolution was keeping failing.
While I was debugging on it, I also found out that the Testcontainers provides `host.testcontainers.internal` for the same purpose and there's no reason not to use it.
https://java.testcontainers.org/features/networking/

Modification
- Use `host.testcontainers.internal` instead of `host.docker.internal`

Result
- The integration tests now run successfully on Linux.

Signed-off-by: minwoox <songmw725@gmail.com>
  • Loading branch information
minwoox committed Feb 28, 2024
1 parent 95048ae commit 40ddc19
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.Testcontainers;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
Expand Down Expand Up @@ -36,11 +37,11 @@ protected void configure() {
withClasspathResourceMapping(LAUNCH_ENVOY_SCRIPT, LAUNCH_ENVOY_SCRIPT_DEST, BindMode.READ_ONLY);
withClasspathResourceMapping(config, CONFIG_DEST, BindMode.READ_ONLY);

withExtraHost("host.docker.internal","host-gateway");

final Integer controlPlanePort = controlPlanePortSupplier.get();
Testcontainers.exposeHostPorts(controlPlanePort);
withCommand(
"/bin/bash", "/usr/local/bin/launch_envoy.sh",
Integer.toString(controlPlanePortSupplier.get()),
Integer.toString(controlPlanePort),
CONFIG_DEST,
"-l", "debug"
);
Expand Down
2 changes: 1 addition & 1 deletion server/src/test/resources/envoy/ads.v3.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static_resources:
- endpoint:
address:
socket_address:
address: host.docker.internal
address: host.testcontainers.internal
port_value: HOST_PORT
http2_protocol_options: {}
name: ads_cluster
2 changes: 1 addition & 1 deletion server/src/test/resources/envoy/ads.v3.delta.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static_resources:
- endpoint:
address:
socket_address:
address: host.docker.internal
address: host.testcontainers.internal
port_value: HOST_PORT
http2_protocol_options: {}
name: ads_cluster
2 changes: 1 addition & 1 deletion server/src/test/resources/envoy/xds.v3.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static_resources:
- endpoint:
address:
socket_address:
address: host.docker.internal
address: host.testcontainers.internal
port_value: HOST_PORT
http2_protocol_options: {}
name: xds_cluster
2 changes: 1 addition & 1 deletion server/src/test/resources/envoy/xds.v3.delta.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static_resources:
- endpoint:
address:
socket_address:
address: host.docker.internal
address: host.testcontainers.internal
port_value: HOST_PORT
http2_protocol_options: {}
name: xds_cluster

0 comments on commit 40ddc19

Please sign in to comment.