Skip to content

Commit

Permalink
feat(#683): Return the gateway address of a network if one is assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Nov 25, 2022
1 parent 45a8935 commit 2d04584
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- 642 Expose container port bindings automatically
- 603 Add default logger that forwards messages to the console (does not support every test environment)
- 683 Return the gateway address (`IDockerContainer.Hostname`) of a network if one is assigned

### Fixed

Expand Down
15 changes: 2 additions & 13 deletions src/Testcontainers/Containers/TestcontainersContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,8 @@ private string GetContainerGateway()
return localhost;
}

var endpointSettings = this.container.NetworkSettings.Networks.TryGetValue("bridge", out var network) ? network : new EndpointSettings();
if (!string.IsNullOrWhiteSpace(endpointSettings.Gateway))
{
return endpointSettings.Gateway;
}

var networkSettings = this.container.NetworkSettings;
if (!string.IsNullOrWhiteSpace(networkSettings.Gateway))
{
return networkSettings.Gateway;
}

return localhost;
var endpointSettings = this.container.NetworkSettings.Networks.Values.FirstOrDefault();
return endpointSettings == null ? localhost : endpointSettings.Gateway;
}
}
}

0 comments on commit 2d04584

Please sign in to comment.