Skip to content

Commit

Permalink
chore: Add test coverage to unbound port bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Aug 6, 2023
1 parent 8344f6a commit da252ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public async Task TestFileExistsInContainer()
.WithImage(CommonImages.Alpine)
.WithEntrypoint(CommonCommands.SleepInfinity)
.WithResourceMapping(_testFile, new FileInfo(targetFilePath1))
.WithResourceMapping(_testFile, targetDirectoryPath1)
.WithResourceMapping(_testFile.Directory, targetDirectoryPath2)
.WithResourceMapping(_testFile.FullName, targetDirectoryPath1)
.WithResourceMapping(_testFile.Directory.FullName, targetDirectoryPath2)
.Build();

// When
Expand All @@ -123,10 +123,10 @@ await container.StartAsync()
await container.CopyAsync(fileContent, targetFilePath2)
.ConfigureAwait(false);

await container.CopyAsync(_testFile, targetDirectoryPath3)
await container.CopyAsync(_testFile.FullName, targetDirectoryPath3)
.ConfigureAwait(false);

await container.CopyAsync(_testFile.Directory, targetDirectoryPath4)
await container.CopyAsync(_testFile.Directory.FullName, targetDirectoryPath4)
.ConfigureAwait(false);

// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public async Task StaticPortBinding()
await using var container = new ContainerBuilder()
.WithImage(CommonImages.Nginx)
.WithPortBinding(hostPort, containerPort)
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(containerPort))
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request =>
request.ForPort(containerPort)))
.Build();

// When
Expand All @@ -178,7 +179,8 @@ public async Task RandomPortBinding()
await using var container = new ContainerBuilder()
.WithImage(CommonImages.Nginx)
.WithPortBinding(containerPort, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(containerPort))
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request =>
request.ForPort(containerPort)))
.Build();

// When
Expand All @@ -189,6 +191,24 @@ await container.StartAsync()
Assert.NotEqual(containerPort, container.GetMappedPublicPort(containerPort));
}

[Fact]
public async Task UnboundPortBindingThrowsException()
{
// Given
await using var container = new ContainerBuilder()
.WithImage(CommonImages.Alpine)
.WithEntrypoint(CommonCommands.SleepInfinity)
.WithPortBinding(80, true)
.Build();

// When
await container.StartAsync()
.ConfigureAwait(false);

// Then
Assert.Throws<InvalidOperationException>(() => container.GetMappedPublicPort(443));
}

[Fact]
public async Task BindMountAndCommand()
{
Expand Down

0 comments on commit da252ad

Please sign in to comment.