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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async ValueTask InitializeAsync()
if (RequiresDockerAttribute.IsSupported)
{
var source = Path.GetFullPath("./goff", Directory.GetCurrentDirectory());
Container = new ContainerBuilder($"{GoFeatureFlagContainerImageTags.Registry}/{GoFeatureFlagContainerImageTags.Image}:{GoFeatureFlagContainerImageTags.Tag}")
Container = new ContainerBuilder($"{TestContainerRegistry.Resolve(GoFeatureFlagContainerImageTags.Registry)}/{GoFeatureFlagContainerImageTags.Image}:{GoFeatureFlagContainerImageTags.Tag}")
.WithPortBinding(1031, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPath("/health").ForPort(1031)))
.WithBindMount(source, "/goff")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Testcontainers.MsSql;
using CommunityToolkit.Aspire.Testing;
using Testcontainers.MsSql;

namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests;

Expand All @@ -25,7 +26,7 @@ public async ValueTask DisposeAsync()

public static async Task<MsSqlContainer> CreateContainerAsync()
{
var container = new MsSqlBuilder($"{Registry}/{Image}:{Tag}")
var container = new MsSqlBuilder($"{TestContainerRegistry.Resolve(Registry)}/{Image}:{Tag}")
.Build();
await container.StartAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async ValueTask InitializeAsync()
{
if (RequiresDockerAttribute.IsSupported)
{
Container = new ContainerBuilder($"{KurrentDBContainerImageTags.Registry}/{KurrentDBContainerImageTags.Image}:{KurrentDBContainerImageTags.Tag}")
Container = new ContainerBuilder($"{TestContainerRegistry.Resolve(KurrentDBContainerImageTags.Registry)}/{KurrentDBContainerImageTags.Image}:{KurrentDBContainerImageTags.Tag}")
.WithPortBinding(2113, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(2113)))
.WithEnvironment("KURRENTDB_CLUSTER_SIZE", "1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async ValueTask InitializeAsync()
//The master key must be at least 16-bytes-long and composed of valid UTF-8 characters.
_masterKey = param.GetDefaultValue();

Container = new ContainerBuilder($"{MeilisearchContainerImageTags.Registry}/{MeilisearchContainerImageTags.Image}:{MeilisearchContainerImageTags.Tag}")
Container = new ContainerBuilder($"{TestContainerRegistry.Resolve(MeilisearchContainerImageTags.Registry)}/{MeilisearchContainerImageTags.Image}:{MeilisearchContainerImageTags.Tag}")
.WithPortBinding(7700, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(7700)))
.WithEnvironment("MEILI_MASTER_KEY", _masterKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async ValueTask InitializeAsync()
{
if (RequiresDockerAttribute.IsSupported)
{
Container = new ContainerBuilder($"{OllamaContainerImageTags.Registry}/{OllamaContainerImageTags.Image}:{OllamaContainerImageTags.Tag}")
Container = new ContainerBuilder($"{TestContainerRegistry.Resolve(OllamaContainerImageTags.Registry)}/{OllamaContainerImageTags.Image}:{OllamaContainerImageTags.Tag}")
.WithPortBinding(11434, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(11434)))
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async ValueTask InitializeAsync()

_password = paramGenerator.GetDefaultValue();

Container = new ContainerBuilder($"{SurrealDbContainerImageTags.Registry}/{SurrealDbContainerImageTags.Image}:{SurrealDbContainerImageTags.Tag}")
Container = new ContainerBuilder($"{TestContainerRegistry.Resolve(SurrealDbContainerImageTags.Registry)}/{SurrealDbContainerImageTags.Image}:{SurrealDbContainerImageTags.Tag}")
.WithPortBinding(_port, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(_port).ForPath("/health")))
.WithEnvironment("SURREAL_USER", _username)
Expand Down
29 changes: 29 additions & 0 deletions tests/CommunityToolkit.Aspire.Testing/TestContainerRegistry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace CommunityToolkit.Aspire.Testing;

/// <summary>
/// Helper for tests that create containers directly via the Testcontainers library (i.e. not through
/// Aspire's container resource model) so that they can also be routed through a custom container registry.
/// </summary>
public static class TestContainerRegistry
{
private const string DockerHubRegistry = "docker.io";

/// <summary>
/// Resolves the registry to use for a Testcontainers image reference. If <paramref name="registry"/> is the
/// default Docker Hub registry and the <c>CUSTOM_CONTAINER_REGISTRY</c> environment variable is set, the
/// custom registry is returned instead to avoid Docker Hub rate limiting. Otherwise, <paramref name="registry"/>
/// is returned unchanged.
/// </summary>
/// <param name="registry">The registry the image would otherwise be pulled from.</param>
public static string Resolve(string registry)
{
string? customRegistry = Environment.GetEnvironmentVariable("CUSTOM_CONTAINER_REGISTRY");

return registry == DockerHubRegistry && !string.IsNullOrEmpty(customRegistry)
? customRegistry
: registry;
}
}
Loading