Skip to content

Commit

Permalink
Merge pull request #292 from 0xced/fix-ExposeAllPorts
Browse files Browse the repository at this point in the history
Fix ArgumentNullException in the ExposeAllPorts method
  • Loading branch information
mariotoffia authored Sep 2, 2023
2 parents 83ec85f + 3567396 commit 6cc2f4e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,40 @@ public void ImplicitPortMappingShouldWork()
}
}

[TestMethod]
[TestCategory("CI")]
public void FullImplicitPortMappingShouldWork()
{
using (
var container =
Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.ExposeAllPorts()
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.Build()
.Start())
{
var endpoint = container.ToHostExposedEndpoint("5432/tcp");
AreNotEqual(0, endpoint.Port);
}
}

[TestMethod]
[TestCategory("CI")]
public void ExposeAllPortsIsMutuallyExclusiveWithExposePort()
{
var exception = ThrowsException<FluentDockerNotSupportedException>(() => Fd.UseContainer().ExposePort(5432).ExposeAllPorts());
AreEqual("ExposeAllPorts is mutually exclusive with ExposePort methods. Do not call ExposePort if you want to expose all ports.", exception.Message);
}

[TestMethod]
[TestCategory("CI")]
public void ExposePortIsMutuallyExclusiveWithExposeAllPorts()
{
var exception = ThrowsException<FluentDockerNotSupportedException>(() => Fd.UseContainer().ExposeAllPorts().ExposePort(5432));
AreEqual("ExposePort is mutually exclusive with ExposeAllPorts methods. Do not call ExposeAllPorts if you want to explicitly expose ports.", exception.Message);
}

[TestMethod]
[TestCategory("CI")]
public void WaitForPortShallWork()
Expand Down
2 changes: 1 addition & 1 deletion Ductus.FluentDocker/Builders/ContainerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private void EnsurePublishAllPortsIsFalse()

private void EnsurePortMappingsIsEmpty()
{
if (_config.CreateParams.PortMappings.Any())
if (_config.CreateParams.PortMappings?.Any() == true)
{
throw new FluentDockerNotSupportedException($"{nameof(ExposeAllPorts)} is mutually exclusive with {nameof(ExposePort)} methods. " +
$"Do not call {nameof(ExposePort)} if you want to expose all ports.");
Expand Down

0 comments on commit 6cc2f4e

Please sign in to comment.