Skip to content
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
2 changes: 1 addition & 1 deletion src/Testcontainers.EventHubs/EventHubsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public override EventHubsContainer Build()
var network = new NetworkBuilder()
.Build();

var container = new AzuriteBuilder()
var container = new AzuriteBuilder("mcr.microsoft.com/azure-storage/azurite:3.28.0")
.WithNetwork(network)
.WithNetworkAliases(AzuriteNetworkAlias)
.Build();
Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.ServiceBus/ServiceBusBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public override ServiceBusContainer Build()
var network = new NetworkBuilder()
.Build();

var container = new MsSqlBuilder()
var container = new MsSqlBuilder("mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04")
.WithNetwork(network)
.WithNetworkAliases(DatabaseNetworkAlias)
.Build();
Expand Down
39 changes: 36 additions & 3 deletions src/Testcontainers/Containers/SocatBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,54 @@ namespace DotNet.Testcontainers.Containers
using Docker.DotNet.Models;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Images;
using JetBrains.Annotations;

/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
[PublicAPI]
public sealed class SocatBuilder : ContainerBuilder<SocatBuilder, SocatContainer, SocatConfiguration>
{
public const string SocatImage = "alpine/socat:1.7.4.3-r0";
[Obsolete("This constant is obsolete and will be removed in the future. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
public const string SocatImage = "alpine/socat:1.7.4.4";

/// <summary>
/// Initializes a new instance of the <see cref="SocatBuilder" /> class.
/// </summary>
[Obsolete("This parameterless constructor is obsolete and will be removed. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
public SocatBuilder()
: this(new SocatConfiguration())
: this(SocatImage)
{
DockerResourceConfiguration = Init().DockerResourceConfiguration;
}

/// <summary>
/// Initializes a new instance of the <see cref="SocatBuilder" /> class.
/// </summary>
/// <param name="image">
/// The full Docker image name, including the image repository and tag
/// (e.g., <c>alpine/socat:1.7.4.4</c>).
/// </param>
/// <remarks>
/// Docker image tags available at <see href="https://hub.docker.com/r/alpine/socat/tags" />.
/// </remarks>
public SocatBuilder(string image)
: this(new DockerImage(image))
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SocatBuilder" /> class.
/// </summary>
/// <param name="image">
/// An <see cref="IImage" /> instance that specifies the Docker image to be used
/// for the container builder configuration.
/// </param>
/// <remarks>
/// Docker image tags available at <see href="https://hub.docker.com/r/alpine/socat/tags" />.
/// </remarks>
public SocatBuilder(IImage image)
: this(new SocatConfiguration())
{
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public DatabaseFixture()
Network = new NetworkBuilder()
.Build();

Container = new AzuriteBuilder()
Container = new AzuriteBuilder("mcr.microsoft.com/azure-storage/azurite:3.28.0")
.WithNetwork(Network)
.WithNetworkAliases(AzuriteNetworkAlias)
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public sealed class Configured : IAsyncLifetime

public Configured()
{
_container = new ContainerBuilder()
.WithImage(CommonImages.Alpine)
_container = new ContainerBuilder(CommonImages.Alpine)
.WithCommand(CommonCommands.SleepInfinity)
.WithConnectionStringProvider(_connectionStringProvider)
.Build();
Expand Down Expand Up @@ -42,8 +41,7 @@ public void GetConnectionStringReturnsExpectedValue()

public sealed class NotConfigured : IAsyncLifetime
{
private readonly IContainer _container = new ContainerBuilder()
.WithImage(CommonImages.Alpine)
private readonly IContainer _container = new ContainerBuilder(CommonImages.Alpine)
.WithCommand(CommonCommands.SleepInfinity)
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SocatContainerTest()
.WithNetworkAliases(HelloWorldAlias)
.Build();

_socatContainer = new SocatBuilder()
_socatContainer = new SocatBuilder(CommonImages.Socat)
.WithNetwork(_network)
.WithTarget(8080, HelloWorldAlias)
.WithTarget(8081, HelloWorldAlias, 8080)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public sealed partial class DeclineLicenseAgreementTest
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public void WithoutAcceptingLicenseAgreementThrowsArgumentException()
{
var exception = Assert.Throws<ArgumentException>(() => new ServiceBusBuilder().Build());
var exception = Assert.Throws<ArgumentException>(() => new ServiceBusBuilder(TestSession.GetImageFromDockerfile()).Build());
Assert.Matches(LicenseAgreementNotAccepted(), exception.Message);
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public void WithLicenseAgreementDeclinedThrowsArgumentException()
{
var exception = Assert.Throws<ArgumentException>(() => new ServiceBusBuilder().WithAcceptLicenseAgreement(false).Build());
var exception = Assert.Throws<ArgumentException>(() => new ServiceBusBuilder(TestSession.GetImageFromDockerfile()).WithAcceptLicenseAgreement(false).Build());
Assert.Matches(LicenseAgreementNotAccepted(), exception.Message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public DatabaseFixture()
Network = new NetworkBuilder()
.Build();

Container = new MsSqlBuilder()
Container = new MsSqlBuilder("mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04")
.WithNetwork(Network)
.WithNetworkAliases(DatabaseNetworkAlias)
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ namespace DotNet.Testcontainers.Tests.Fixtures
{
using System.Collections.Generic;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Images;

public abstract class DockerMTls : ProtectDockerDaemonSocket
{
public DockerMTls(string dockerImageVersion)
: base(new ContainerBuilder(), dockerImageVersion)
: base(new ContainerBuilder("docker:" + dockerImageVersion + "-dind"))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ namespace DotNet.Testcontainers.Tests.Fixtures
{
using System.Collections.Generic;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Images;
using JetBrains.Annotations;

[UsedImplicitly]
public sealed class DockerTlsFixture : ProtectDockerDaemonSocket
{
public DockerTlsFixture()
: base(new ContainerBuilder()
.WithCommand("--tlsverify=false"), "29.0.0")
: base(new ContainerBuilder("docker:29.0.0-dind")
.WithCommand("--tlsverify=false"))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public abstract class ProtectDockerDaemonSocket : IAsyncLifetime

private readonly IContainer _container;

protected ProtectDockerDaemonSocket(ContainerBuilder containerConfiguration, string dockerImageVersion)
protected ProtectDockerDaemonSocket(ContainerBuilder containerBuilder)
{
_container = containerConfiguration
.WithImage(new DockerImage("docker", null, dockerImageVersion + "-dind"))
_container = containerBuilder
.WithPrivileged(true)
.WithPortBinding(TlsPort, true)
.WithBindMount(_hostCertsDirectoryPath, _containerCertsDirectoryPath, AccessMode.ReadWrite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public static class TestcontainersContainerTest
{
public sealed class WithConfiguration
{
[Fact]
public void ShouldThrowArgumentNullExceptionWhenBuildConfigurationHasNoImage()
[Theory]
[InlineData(null)]
[InlineData("")]
public void ShouldThrowArgumentExceptionWhenContainerBuilderHasNoImage(string image)
{
Assert.Throws<ArgumentException>(() => _ = new ContainerBuilder().Build());
Assert.Throws<ArgumentException>(() => _ = new ContainerBuilder(image));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class ToxiproxyContainerTest : IAsyncLifetime

public ToxiproxyContainerTest()
{
_redisContainer = new RedisBuilder()
_redisContainer = new RedisBuilder("redis:7.0")
.WithNetwork(_network)
.WithNetworkAliases(RedisNetworkAlias)
.Build();
Expand Down