Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add test coverage to unbound port bindings #966

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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