Skip to content

Commit

Permalink
chore: Remove minor Sonar findings
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Apr 28, 2023
1 parent 10a5153 commit 90a3006
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 36 deletions.
3 changes: 1 addition & 2 deletions src/Testcontainers/Builders/AbstractBuilder`4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ public abstract class AbstractBuilder<TBuilderEntity, TResourceEntity, TCreateRe
protected AbstractBuilder(TConfigurationEntity dockerResourceConfiguration)
{
_ = TestcontainersSettings.SettingsInitialized.WaitOne(TimeSpan.FromSeconds(5));
DockerResourceConfiguration = dockerResourceConfiguration;
}

/// <summary>
/// Gets the Docker resource configuration.
/// </summary>
protected virtual TConfigurationEntity DockerResourceConfiguration { get; }
protected abstract TConfigurationEntity DockerResourceConfiguration { get; }

/// <inheritdoc cref="IAbstractBuilder{TBuilderEntity, TContainerEntity, TCreateResourceEntity}" />
public TBuilderEntity WithDockerEndpoint(string endpoint)
Expand Down
33 changes: 1 addition & 32 deletions src/Testcontainers/Containers/PortForwarding.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace DotNet.Testcontainers.Containers
{
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
Expand Down Expand Up @@ -97,26 +95,6 @@ private PortForwardingBuilder(PortForwardingConfiguration resourceConfiguration)
/// <inheritdoc />
protected override PortForwardingConfiguration DockerResourceConfiguration { get; }

/// <summary>
/// Exposes the host ports using SSH port forwarding.
/// </summary>
/// <param name="ports">The host ports to forward.</param>
/// <returns>A configured instance of <see cref="PortForwardingBuilder" />.</returns>
public PortForwardingBuilder WithExposedHostPort(params int[] ports)
{
return WithExposedHostPort(ports.Select(port => port.ToString(CultureInfo.InvariantCulture)).ToArray());
}

/// <summary>
/// Exposes the host ports to containers in the same network.
/// </summary>
/// <param name="exposedHostPorts">The host ports.</param>
/// <returns>A configured instance of <see cref="PortForwardingBuilder" />.</returns>
public PortForwardingBuilder WithExposedHostPort(params string[] exposedHostPorts)
{
return Merge(DockerResourceConfiguration, new PortForwardingConfiguration(exposedHostPorts: exposedHostPorts));
}

/// <inheritdoc />
public override PortForwardingContainer Build()
{
Expand Down Expand Up @@ -187,15 +165,12 @@ public sealed class PortForwardingConfiguration : ContainerConfiguration
/// </summary>
/// <param name="username">The OpenSSH daemon username.</param>
/// <param name="password">The OpenSSH daemon password.</param>
/// <param name="exposedHostPorts">A list of exposed host ports.</param>
public PortForwardingConfiguration(
string username = null,
string password = null,
IEnumerable<string> exposedHostPorts = null)
string password = null)
{
Username = username;
Password = password;
ExposedHostPorts = exposedHostPorts;
}

/// <summary>
Expand Down Expand Up @@ -238,7 +213,6 @@ public PortForwardingConfiguration(PortForwardingConfiguration oldValue, PortFor
{
Username = BuildConfiguration.Combine(oldValue.Username, newValue.Username);
Password = BuildConfiguration.Combine(oldValue.Password, newValue.Password);
ExposedHostPorts = BuildConfiguration.Combine(oldValue.ExposedHostPorts, newValue.ExposedHostPorts);
}

/// <summary>
Expand All @@ -250,11 +224,6 @@ public PortForwardingConfiguration(PortForwardingConfiguration oldValue, PortFor
/// Gets the OpenSSH daemon password.
/// </summary>
public string Password { get; }

/// <summary>
/// Gets a list of exposed host ports.
/// </summary>
public IEnumerable<string> ExposedHostPorts { get; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public PortForwardingNetworkConfiguration(HostedService fixture)
[UsedImplicitly]
public sealed class HostedService : IAsyncLifetime
{
private readonly CancellationTokenSource _cancellationTokenSource = new();
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();

private readonly TcpListener _tcpListener = new(new IPEndPoint(IPAddress.Any, 0));
private readonly TcpListener _tcpListener = new TcpListener(new IPEndPoint(IPAddress.Any, 0));

public HostedService()
{
Expand Down

0 comments on commit 90a3006

Please sign in to comment.