Skip to content

Commit

Permalink
fix: correct default for get_host_ip_address in case of unix or `…
Browse files Browse the repository at this point in the history
…npipe` (#613)

`IpAddr` can't be parsed from `localhost`, it expects domain.

We could use `url::Host`, but it would be a breaking change and method
must be renamed in that case
  • Loading branch information
DDtKey authored Apr 29, 2024
1 parent 95f67ec commit 8dd6406
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion testcontainers/src/core/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl Client {
.into_iter()
.filter_map(|ipam_cfg| ipam_cfg.gateway)
.next()
.unwrap_or_else(|| "localhost".to_string()),
.unwrap_or_else(|| "127.0.0.1".to_string()),
_ => unreachable!("docker host is already validated in the config"),
}
}
Expand Down
8 changes: 4 additions & 4 deletions testcontainers/src/core/containers/async_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ where

/// Returns the host ip address of docker container
pub async fn get_host_ip_address(&self) -> IpAddr {
self.docker_client
.docker_host_ip_address()
.await
let host_ip = self.docker_client.docker_host_ip_address().await;

host_ip
.parse()
.expect("invalid host IP")
.unwrap_or_else(|e| panic!("invalid host ip: '{host_ip}', error: {e}"))
}

pub async fn exec(&self, cmd: ExecCommand) {
Expand Down
4 changes: 2 additions & 2 deletions testcontainers/src/runners/sync_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ mod tests {
fn sync_run_command_should_expose_only_requested_ports() {
let image = GenericImage::new("hello-world", "latest");
let container = RunnableImage::from(image)
.with_mapped_port((123, 456))
.with_mapped_port((555, 888))
.with_mapped_port((124, 456))
.with_mapped_port((556, 888))
.start();

let container_details = inspect(container.id());
Expand Down

0 comments on commit 8dd6406

Please sign in to comment.