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

feat: Support digest in IImage, DockerImage and in the WithImage(string) implementation #1249

Merged
merged 8 commits into from
Sep 15, 2024
2 changes: 1 addition & 1 deletion src/Testcontainers/Builders/DockerConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DotNet.Testcontainers.Builders
namespace DotNet.Testcontainers.Builders
{
using System;
using System.IO;
Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers/Builders/SourceGenerationContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DotNet.Testcontainers.Builders
namespace DotNet.Testcontainers.Builders
{
using System.Text.Json.Serialization;

Expand Down
3 changes: 1 addition & 2 deletions src/Testcontainers/Clients/DockerImageOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public async Task CreateAsync(IImage image, IDockerRegistryAuthenticationConfigu
{
var createParameters = new ImagesCreateParameters
{
FromImage = image.FullName.Replace(":" + image.Tag, string.Empty), // Workaround until https://github.com/dotnet/Docker.DotNet/issues/595 is fixed.
Tag = image.Tag,
FromImage = image.FullName
};

var authConfig = new AuthConfig
Expand Down
13 changes: 11 additions & 2 deletions src/Testcontainers/Images/DockerImage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DotNet.Testcontainers.Images
namespace DotNet.Testcontainers.Images
{
using System;
using System.Globalization;
Expand Down Expand Up @@ -117,7 +117,16 @@ public DockerImage(
public string Digest => _digit;

/// <inheritdoc />
public string FullName => $"{Registry}/{Repository}:{Tag}".Trim(TrimChars);
public string FullName
{
get
{
var registry = string.IsNullOrEmpty(Registry) ? string.Empty : $"{Registry}/";
var tag = string.IsNullOrEmpty(Tag) ? string.Empty : $":{Tag}";
var digest = string.IsNullOrEmpty(Digest) ? string.Empty : $"@{Digest}";
return $"{registry}{Repository}{tag}{digest}";
}
}

/// <inheritdoc />
[Obsolete("We will remove this property, it does not follow the DSL. Use the 'Repository' property instead.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,23 @@ await container.StartAsync()
Assert.EndsWith(name, container.Name);
}

[Fact]
public async Task PullDigest()
{
// Given
await using var container = new ContainerBuilder()
.WithImage("alpine@sha256:3451da08fc6ef554a100da3e2df5ac6d598c82f2a774d5f6ed465c3d80cd163a")
.WithEntrypoint(CommonCommands.SleepInfinity)
.Build();

// When
var exception = await Record.ExceptionAsync(() => container.StartAsync())
.ConfigureAwait(true);

// Then
Assert.Null(exception);
}

[Fact]
public async Task PullPolicyNever()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void ShouldNotThrowArgumentExceptionIfImageTagHasUppercaseCharacters(stri

[Theory]
[ClassData(typeof(DockerImageFixture))]
public void WhenImageNameGetsAssigned(DockerImageFixtureSerializable serializable, string image, string _)
public void WhenImageNameGetsAssigned(DockerImageFixtureSerializable serializable, string image, string fullName)
{
// Given
var expected = serializable.Image;
Expand All @@ -67,7 +67,7 @@ public void WhenImageNameGetsAssigned(DockerImageFixtureSerializable serializabl
Assert.Equal(expected.Digest, actual.Digest);
Assert.Equal(expected.FullName, actual.FullName);
Assert.Equal(expected.Name, actual.Name);
// Assert.Equal(fullName, actual.FullName);
Assert.Equal(fullName, actual.FullName);
}

[Fact]
Expand Down
Loading