Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn authored Oct 14, 2023
2 parents 415af6a + 44a1d3a commit db51bb0
Show file tree
Hide file tree
Showing 28 changed files with 155 additions and 159 deletions.
2 changes: 1 addition & 1 deletion Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
<PackageReference Update="BouncyCastle.Cryptography" Version="2.2.1" />
<PackageReference Update="SharpZipLib" Version="1.4.2" />
<PackageReference Update="SSH.NET" Version="2020.0.2" />
<PackageReference Update="SSH.NET" Version="2023.0.0" />
<PackageReference Update="System.Text.Json" Version="6.0.8" />
<!-- Unit and integration test dependencies: -->
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.7.2" />
Expand Down
7 changes: 7 additions & 0 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Couchbase.Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.CouchDb.Tests", "tests\Testcontainers.CouchDb.Tests\Testcontainers.CouchDb.Tests.csproj", "{E4520FB1-4466-4DCA-AD08-4075102C68D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Databases.Tests", "tests\Testcontainers.Databases.Tests\Testcontainers.Databases.Tests.csproj", "{DA54916E-1128-4200-B6AE-9F5BF02D832D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.DynamoDb.Tests", "tests\Testcontainers.DynamoDb.Tests\Testcontainers.DynamoDb.Tests.csproj", "{101515E6-74C1-40F9-85C8-871F742A378D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Elasticsearch.Tests", "tests\Testcontainers.Elasticsearch.Tests\Testcontainers.Elasticsearch.Tests.csproj", "{DD5B3678-468F-4D73-AECE-705E3D66CD43}"
Expand Down Expand Up @@ -302,6 +304,10 @@ Global
{E4520FB1-4466-4DCA-AD08-4075102C68D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4520FB1-4466-4DCA-AD08-4075102C68D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4520FB1-4466-4DCA-AD08-4075102C68D3}.Release|Any CPU.Build.0 = Release|Any CPU
{DA54916E-1128-4200-B6AE-9F5BF02D832D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA54916E-1128-4200-B6AE-9F5BF02D832D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA54916E-1128-4200-B6AE-9F5BF02D832D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA54916E-1128-4200-B6AE-9F5BF02D832D}.Release|Any CPU.Build.0 = Release|Any CPU
{101515E6-74C1-40F9-85C8-871F742A378D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{101515E6-74C1-40F9-85C8-871F742A378D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{101515E6-74C1-40F9-85C8-871F742A378D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -457,6 +463,7 @@ Global
{BD445A54-F411-4758-955E-397A1E98680C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{809322BA-D690-4F2B-B884-23F895663963} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{E4520FB1-4466-4DCA-AD08-4075102C68D3} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{DA54916E-1128-4200-B6AE-9F5BF02D832D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{101515E6-74C1-40F9-85C8-871F742A378D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{DD5B3678-468F-4D73-AECE-705E3D66CD43} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.ClickHouse/ClickHouseContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Testcontainers.ClickHouse;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class ClickHouseContainer : DockerContainer
public sealed class ClickHouseContainer : DockerContainer, IDatabaseContainer
{
private readonly ClickHouseConfiguration _configuration;

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.MariaDb/MariaDbContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Testcontainers.MariaDb;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class MariaDbContainer : DockerContainer
public sealed class MariaDbContainer : DockerContainer, IDatabaseContainer
{
private readonly MariaDbConfiguration _configuration;

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.MsSql/MsSqlContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Testcontainers.MsSql;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class MsSqlContainer : DockerContainer
public sealed class MsSqlContainer : DockerContainer, IDatabaseContainer
{
private readonly MsSqlConfiguration _configuration;

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.MySql/MySqlContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Testcontainers.MySql;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class MySqlContainer : DockerContainer
public sealed class MySqlContainer : DockerContainer, IDatabaseContainer
{
private readonly MySqlConfiguration _configuration;

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.Oracle/OracleContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Testcontainers.Oracle;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class OracleContainer : DockerContainer
public sealed class OracleContainer : DockerContainer, IDatabaseContainer
{
private readonly OracleConfiguration _configuration;

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.PostgreSql/PostgreSqlContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Testcontainers.PostgreSql;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class PostgreSqlContainer : DockerContainer
public sealed class PostgreSqlContainer : DockerContainer, IDatabaseContainer
{
private readonly PostgreSqlConfiguration _configuration;

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.SqlEdge/SqlEdgeContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Testcontainers.SqlEdge;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class SqlEdgeContainer : DockerContainer
public sealed class SqlEdgeContainer : DockerContainer, IDatabaseContainer
{
private readonly SqlEdgeConfiguration _configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ContainerConfigurationConverter(IContainerConfiguration configuration)

private static string GetQualifiedPort(string containerPort)
{
return new[] { UdpPortSuffix, TcpPortSuffix, SctpPortSuffix }.Any(portSuffix => containerPort.EndsWith(portSuffix, StringComparison.OrdinalIgnoreCase)) ? containerPort.ToLowerInvariant() : containerPort + TcpPortSuffix;
return Array.Exists(new[] { UdpPortSuffix, TcpPortSuffix, SctpPortSuffix }, portSuffix => containerPort.EndsWith(portSuffix, StringComparison.OrdinalIgnoreCase)) ? containerPort.ToLowerInvariant() : containerPort + TcpPortSuffix;
}

private sealed class ToCollection : CollectionConverter<string, string>
Expand Down
26 changes: 5 additions & 21 deletions src/Testcontainers/Clients/DockerContainerOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,11 @@ public async Task<IEnumerable<ContainerListResponse>> GetAllAsync(FilterByProper
.ConfigureAwait(false);
}

public Task<ContainerInspectResponse> ByIdAsync(string id, CancellationToken ct = default)
{
return ByPropertyAsync("id", id, ct);
}

public Task<ContainerInspectResponse> ByNameAsync(string name, CancellationToken ct = default)
{
return ByPropertyAsync("name", name, ct);
}

public async Task<ContainerInspectResponse> ByPropertyAsync(string property, string value, CancellationToken ct = default)
public async Task<ContainerInspectResponse> ByIdAsync(string id, CancellationToken ct = default)
{
try
{
return await Docker.Containers.InspectContainerAsync(value, ct)
return await Docker.Containers.InspectContainerAsync(id, ct)
.ConfigureAwait(false);
}
catch (DockerApiException)
Expand All @@ -65,18 +55,12 @@ public async Task<bool> ExistsWithIdAsync(string id, CancellationToken ct = defa
return response != null;
}

public async Task<bool> ExistsWithNameAsync(string name, CancellationToken ct = default)
public async Task<long> GetExitCodeAsync(string id, CancellationToken ct = default)
{
var response = await ByNameAsync(name, ct)
var response = await Docker.Containers.WaitContainerAsync(id, ct)
.ConfigureAwait(false);

return response != null;
}

public async Task<long> GetExitCodeAsync(string id, CancellationToken ct = default)
{
return (await Docker.Containers.WaitContainerAsync(id, ct)
.ConfigureAwait(false)).StatusCode;
return response.StatusCode;
}

public async Task<(string Stdout, string Stderr)> GetLogsAsync(string id, TimeSpan since, TimeSpan until, bool timestampsEnabled = true, CancellationToken ct = default)
Expand Down
26 changes: 4 additions & 22 deletions src/Testcontainers/Clients/DockerImageOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,11 @@ public async Task<IEnumerable<ImagesListResponse>> GetAllAsync(FilterByProperty
.ConfigureAwait(false);
}

public Task<ImageInspectResponse> ByIdAsync(string id, CancellationToken ct = default)
{
return ByPropertyAsync("id", id, ct);
}

public Task<ImageInspectResponse> ByNameAsync(string name, CancellationToken ct = default)
{
return ByPropertyAsync("reference", name, ct);
}

public async Task<ImageInspectResponse> ByPropertyAsync(string property, string value, CancellationToken ct = default)
public async Task<ImageInspectResponse> ByIdAsync(string id, CancellationToken ct = default)
{
try
{
return await Docker.Images.InspectImageAsync(value, ct)
return await Docker.Images.InspectImageAsync(id, ct)
.ConfigureAwait(false);
}
catch (DockerApiException)
Expand All @@ -68,14 +58,6 @@ public async Task<bool> ExistsWithIdAsync(string id, CancellationToken ct = defa
return response != null;
}

public async Task<bool> ExistsWithNameAsync(string name, CancellationToken ct = default)
{
var response = await ByNameAsync(name, ct)
.ConfigureAwait(false);

return response != null;
}

public async Task CreateAsync(IImage image, IDockerRegistryAuthenticationConfiguration dockerRegistryAuthConfig, CancellationToken ct = default)
{
var createParameters = new ImagesCreateParameters
Expand Down Expand Up @@ -108,7 +90,7 @@ public async Task<string> BuildAsync(IImageFromDockerfileConfiguration configura
{
var image = configuration.Image;

var imageExists = await ExistsWithNameAsync(image.FullName, ct)
var imageExists = await ExistsWithIdAsync(image.FullName, ct)
.ConfigureAwait(false);

if (imageExists && configuration.DeleteIfExists.HasValue && configuration.DeleteIfExists.Value)
Expand Down Expand Up @@ -143,7 +125,7 @@ await DeleteAsync(image, ct)
await Docker.Images.BuildImageFromDockerfileAsync(buildParameters, dockerfileArchiveStream, Array.Empty<AuthConfig>(), new Dictionary<string, string>(), _traceProgress, ct)
.ConfigureAwait(false);

var imageHasBeenCreated = await ExistsWithNameAsync(image.FullName, ct)
var imageHasBeenCreated = await ExistsWithIdAsync(image.FullName, ct)
.ConfigureAwait(false);

if (!imageHasBeenCreated)
Expand Down
22 changes: 2 additions & 20 deletions src/Testcontainers/Clients/DockerNetworkOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,11 @@ public async Task<IEnumerable<NetworkResponse>> GetAllAsync(FilterByProperty fil
.ConfigureAwait(false);
}

public Task<NetworkResponse> ByIdAsync(string id, CancellationToken ct = default)
{
return ByPropertyAsync("id", id, ct);
}

public Task<NetworkResponse> ByNameAsync(string name, CancellationToken ct = default)
{
return ByPropertyAsync("name", name, ct);
}

public async Task<NetworkResponse> ByPropertyAsync(string property, string value, CancellationToken ct = default)
public async Task<NetworkResponse> ByIdAsync(string id, CancellationToken ct = default)
{
try
{
return await Docker.Networks.InspectNetworkAsync(value, ct)
return await Docker.Networks.InspectNetworkAsync(id, ct)
.ConfigureAwait(false);
}
catch (DockerApiException)
Expand All @@ -63,14 +53,6 @@ public async Task<bool> ExistsWithIdAsync(string id, CancellationToken ct = defa
return response != null;
}

public async Task<bool> ExistsWithNameAsync(string name, CancellationToken ct = default)
{
var response = await ByNameAsync(name, ct)
.ConfigureAwait(false);

return response != null;
}

public async Task<string> CreateAsync(INetworkConfiguration configuration, CancellationToken ct = default)
{
var createParameters = new NetworksCreateParameters
Expand Down
1 change: 1 addition & 0 deletions src/Testcontainers/Clients/DockerSystemOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public async Task<bool> GetIsWindowsEngineEnabled(CancellationToken ct = default
{
var version = await GetVersionAsync(ct)
.ConfigureAwait(false);

return version.Os.IndexOf("Windows", StringComparison.OrdinalIgnoreCase) > -1;
}

Expand Down
22 changes: 2 additions & 20 deletions src/Testcontainers/Clients/DockerVolumeOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,11 @@ public async Task<IEnumerable<VolumeResponse>> GetAllAsync(FilterByProperty filt
return response.Volumes;
}

public Task<VolumeResponse> ByIdAsync(string id, CancellationToken ct = default)
{
return ByPropertyAsync("id", id, ct);
}

public Task<VolumeResponse> ByNameAsync(string name, CancellationToken ct = default)
{
return ByPropertyAsync("name", name, ct);
}

public async Task<VolumeResponse> ByPropertyAsync(string property, string value, CancellationToken ct = default)
public async Task<VolumeResponse> ByIdAsync(string id, CancellationToken ct = default)
{
try
{
return await Docker.Volumes.InspectAsync(value, ct)
return await Docker.Volumes.InspectAsync(id, ct)
.ConfigureAwait(false);
}
catch (DockerApiException)
Expand All @@ -67,14 +57,6 @@ public async Task<bool> ExistsWithIdAsync(string id, CancellationToken ct = defa
return response != null;
}

public async Task<bool> ExistsWithNameAsync(string name, CancellationToken ct = default)
{
var response = await ByNameAsync(name, ct)
.ConfigureAwait(false);

return response != null;
}

public async Task<string> CreateAsync(IVolumeConfiguration configuration, CancellationToken ct = default)
{
var createParameters = new VolumesCreateParameters
Expand Down
6 changes: 0 additions & 6 deletions src/Testcontainers/Clients/IHasListOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ internal interface IHasListOperations<TListEntity, TInspectEntity>

Task<TInspectEntity> ByIdAsync(string id, CancellationToken ct = default);

Task<TInspectEntity> ByNameAsync(string name, CancellationToken ct = default);

Task<TInspectEntity> ByPropertyAsync(string property, string value, CancellationToken ct = default);

Task<bool> ExistsWithIdAsync(string id, CancellationToken ct = default);

Task<bool> ExistsWithNameAsync(string name, CancellationToken ct = default);
}
}
4 changes: 2 additions & 2 deletions src/Testcontainers/Clients/TestcontainersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public async Task<string> RunAsync(IContainerConfiguration configuration, Cancel
.ConfigureAwait(false);
}

var cachedImage = await Image.ByNameAsync(configuration.Image.FullName, ct)
var cachedImage = await Image.ByIdAsync(configuration.Image.FullName, ct)
.ConfigureAwait(false);

if (configuration.ImagePullPolicy(cachedImage))
Expand Down Expand Up @@ -323,7 +323,7 @@ await Task.WhenAll(configuration.ResourceMappings.Values.Select(resourceMapping
/// <inheritdoc />
public async Task<string> BuildAsync(IImageFromDockerfileConfiguration configuration, CancellationToken ct = default)
{
var cachedImage = await Image.ByNameAsync(configuration.Image.FullName, ct)
var cachedImage = await Image.ByIdAsync(configuration.Image.FullName, ct)
.ConfigureAwait(false);

if (configuration.ImageBuildPolicy(cachedImage))
Expand Down
14 changes: 3 additions & 11 deletions src/Testcontainers/Containers/DockerContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace DotNet.Testcontainers.Containers
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Docker.DotNet;
using Docker.DotNet.Models;
using DotNet.Testcontainers.Clients;
using DotNet.Testcontainers.Configurations;
Expand Down Expand Up @@ -472,23 +471,16 @@ protected virtual async Task UnsafeStopAsync(CancellationToken ct = default)
await _client.StopAsync(_container.ID, ct)
.ConfigureAwait(false);

try
{
_container = await _client.Container.ByIdAsync(_container.ID, ct)
.ConfigureAwait(false);
}
catch (DockerApiException)
{
_container = new ContainerInspectResponse();
}
_container = await _client.Container.ByIdAsync(_container.ID, ct)
.ConfigureAwait(false);

Stopped?.Invoke(this, EventArgs.Empty);
}

/// <inheritdoc />
protected override bool Exists()
{
return ContainerHasBeenCreatedStates.HasFlag(State);
return _container != null && ContainerHasBeenCreatedStates.HasFlag(State);
}
}
}
18 changes: 18 additions & 0 deletions src/Testcontainers/Containers/IDatabaseContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace DotNet.Testcontainers.Containers
{
using JetBrains.Annotations;

/// <summary>
/// Represents a database container instance that can be accessed with an ADO.NET provider.
/// </summary>
[PublicAPI]
public interface IDatabaseContainer
{
/// <summary>
/// Gets the database connection string.
/// </summary>
/// <returns>The database connection string.</returns>
[NotNull]
string GetConnectionString();
}
}
2 changes: 1 addition & 1 deletion src/Testcontainers/Images/FutureDockerImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected override async Task UnsafeCreateAsync(CancellationToken ct = default)
_ = await _client.BuildAsync(_configuration, ct)
.ConfigureAwait(false);

_image = await _client.Image.ByNameAsync(_configuration.Image.FullName, ct)
_image = await _client.Image.ByIdAsync(_configuration.Image.FullName, ct)
.ConfigureAwait(false);
}

Expand Down
Loading

0 comments on commit db51bb0

Please sign in to comment.