Skip to content

Commit

Permalink
Throw the new DockerUnavailableException when Docker is not available
Browse files Browse the repository at this point in the history
(because it is either not running or misconfigured)

The `ArgumentException` was not the appropriate exception to throw since the root of the problem is not a bad argument but the state of the system which is wrong.
  • Loading branch information
0xced committed Nov 26, 2024
1 parent 49ef7dc commit 9fccae7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
12 changes: 9 additions & 3 deletions src/Testcontainers/Builders/AbstractBuilder`4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ protected virtual void Validate()
_ = Guard.Argument(DockerResourceConfiguration.Logger, nameof(IResourceConfiguration<TCreateResourceEntity>.Logger))
.NotNull();

const string containerRuntimeNotFound = "Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:\nhttps://dotnet.testcontainers.org/custom_configuration/";
_ = Guard.Argument(DockerResourceConfiguration.DockerEndpointAuthConfig, nameof(IResourceConfiguration<TCreateResourceEntity>.DockerEndpointAuthConfig))
.ThrowIf(argument => argument.Value == null, argument => new ArgumentException(containerRuntimeNotFound, argument.Name));
if (DockerResourceConfiguration.DockerEndpointAuthConfig == null)
{
var message = TestcontainersSettings.UnavailableEndpoints.Count == 0
? "Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured."
: $"Docker is either not running or misconfigured. Please ensure that Docker is available at {string.Join(" or ", TestcontainersSettings.UnavailableEndpoints)}";

throw new DockerUnavailableException(message + "\nYou can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. " +

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.ActiveMq.ArtemisContainerTest+CustomCredentialsConfiguration ► EstablishesConnection

Failed test found in: Testcontainers.ActiveMq.Tests.trx Error: DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at Testcontainers.ActiveMq.ArtemisBuilder.Validate() in /_/src/Testcontainers.ActiveMq/ArtemisBuilder.cs:line 83
   at Testcontainers.ActiveMq.ArtemisBuilder.Build() in /_/src/Testcontainers.ActiveMq/ArtemisBuilder.cs:line 64
   at Testcontainers.ActiveMq.ArtemisContainerTest.CustomCredentialsConfiguration..ctor() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.ActiveMq.Tests/ArtemisContainerTest.cs:line 88
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.ActiveMq.ArtemisContainerTest+DefaultCredentialsConfiguration ► EstablishesConnection

Failed test found in: Testcontainers.ActiveMq.Tests.trx Error: DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at Testcontainers.ActiveMq.ArtemisBuilder.Validate() in /_/src/Testcontainers.ActiveMq/ArtemisBuilder.cs:line 83
   at Testcontainers.ActiveMq.ArtemisBuilder.Build() in /_/src/Testcontainers.ActiveMq/ArtemisBuilder.cs:line 64
   at Testcontainers.ActiveMq.ArtemisContainerTest.DefaultCredentialsConfiguration..ctor() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.ActiveMq.Tests/ArtemisContainerTest.cs:line 75
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.ActiveMq.ArtemisContainerTest+NoAuthCredentialsConfiguration ► EstablishesConnection

Failed test found in: Testcontainers.ActiveMq.Tests.trx Error: DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at Testcontainers.ActiveMq.ArtemisBuilder.Validate() in /_/src/Testcontainers.ActiveMq/ArtemisBuilder.cs:line 83
   at Testcontainers.ActiveMq.ArtemisBuilder.Build() in /_/src/Testcontainers.ActiveMq/ArtemisBuilder.cs:line 64
   at Testcontainers.ActiveMq.ArtemisContainerTest.NoAuthCredentialsConfiguration..ctor() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.ActiveMq.Tests/ArtemisContainerTest.cs:line 97
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.Tests.DependsOnTest ► DependsOnCreatesDependentResources

Failed test found in: Testcontainers.Platform.Linux.Tests.trx Error: DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at DotNet.Testcontainers.Builders.ContainerBuilder.Build() in /_/src/Testcontainers/Builders/ContainerBuilder.cs:line 56
   at Testcontainers.Tests.DependsOnTest.InitializeAsync() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/DependsOnTest.cs:line 20

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.Tests.LoggerTest+SharedCollectionTest1 ► LogContainerRuntimeInformationOnce(_: 0)

Failed test found in: Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Testcontainers.Platform.Linux.Tests.trx Error: DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at DotNet.Testcontainers.Builders.ContainerBuilder.Build() in /_/src/Testcontainers/Builders/ContainerBuilder.cs:line 56
   at Testcontainers.Tests.LoggerTest.InitializeAsync() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/LoggerTest.cs:line 14

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.Tests.PortForwardingTest+PortForwardingDefaultConfiguration ► EstablishesHostConnection

Failed test found in: Testcontainers.Platform.Linux.Tests.trx Error: DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at DotNet.Testcontainers.Builders.ContainerBuilder.Build() in /_/src/Testcontainers/Builders/ContainerBuilder.cs:line 56
   at Testcontainers.Tests.PortForwardingTest.PortForwardingDefaultConfiguration..ctor(HostedService fixture) in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/PortForwardingTest.cs:line 40
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.Tests.PortForwardingTest+PortForwardingNetworkConfiguration ► EstablishesHostConnection

Failed test found in: Testcontainers.Platform.Linux.Tests.trx Error: DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.NetworkBuilder.Validate() in /_/src/Testcontainers/Builders/NetworkBuilder.cs:line 84
   at DotNet.Testcontainers.Builders.NetworkBuilder.Build() in /_/src/Testcontainers/Builders/NetworkBuilder.cs:line 71
   at Testcontainers.Tests.PortForwardingTest.PortForwardingNetworkConfiguration..ctor(HostedService fixture) in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/PortForwardingTest.cs:line 55
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.Tests.ReusableResourceTest ► ShouldReuseExistingResource

Failed test found in: Testcontainers.Platform.Linux.Tests.trx Error: DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at DotNet.Testcontainers.Builders.ContainerBuilder.Build() in /_/src/Testcontainers/Builders/ContainerBuilder.cs:line 56
   at Testcontainers.Tests.ReusableResourceTest.InitializeAsync() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs:line 31

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.Tests.ReusableResourceTest+UnsupportedBuilderConfigurationTest+ContainerBuilderTest ► EnabledAutoRemoveThrowsException

Failed test found in: Testcontainers.Platform.Linux.Tests.trx Error: Assert.Throws() Failure: Exception type was not an exact match Expected: typeof(System.ArgumentException) Actual: typeof(DotNet.Testcontainers.DockerUnavailableException) ---- DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
Assert.Throws() Failure: Exception type was not an exact match
Expected: typeof(System.ArgumentException)
Actual:   typeof(DotNet.Testcontainers.DockerUnavailableException)
---- DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at Testcontainers.Tests.ReusableResourceTest.UnsupportedBuilderConfigurationTest.ContainerBuilderTest.EnabledAutoRemoveThrowsException() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs:line 142
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
----- Inner Stack Trace -----
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at DotNet.Testcontainers.Builders.ContainerBuilder.Build() in /_/src/Testcontainers/Builders/ContainerBuilder.cs:line 56
   at Testcontainers.Tests.ReusableResourceTest.UnsupportedBuilderConfigurationTest.ContainerBuilderTest.<>c__DisplayClass1_0.<EnabledAutoRemoveThrowsException>b__0() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs:line 142

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.Tests.ReusableResourceTest+UnsupportedBuilderConfigurationTest+ContainerBuilderTest ► EnabledCleanUpThrowsException

Failed test found in: Testcontainers.Platform.Linux.Tests.trx Error: Assert.Throws() Failure: Exception type was not an exact match Expected: typeof(System.ArgumentException) Actual: typeof(DotNet.Testcontainers.DockerUnavailableException) ---- DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
Assert.Throws() Failure: Exception type was not an exact match
Expected: typeof(System.ArgumentException)
Actual:   typeof(DotNet.Testcontainers.DockerUnavailableException)
---- DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at Testcontainers.Tests.ReusableResourceTest.UnsupportedBuilderConfigurationTest.ContainerBuilderTest.EnabledCleanUpThrowsException() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs:line 129
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
----- Inner Stack Trace -----
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.ContainerBuilder`3.Validate() in /_/src/Testcontainers/Builders/ContainerBuilder`3.cs:line 383
   at DotNet.Testcontainers.Builders.ContainerBuilder.Build() in /_/src/Testcontainers/Builders/ContainerBuilder.cs:line 56
   at Testcontainers.Tests.ReusableResourceTest.UnsupportedBuilderConfigurationTest.ContainerBuilderTest.<>c__DisplayClass0_0.<EnabledCleanUpThrowsException>b__0() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs:line 129

Check failure on line 150 in src/Testcontainers/Builders/AbstractBuilder`4.cs

View workflow job for this annotation

GitHub Actions / Test Report

Testcontainers.Tests.ReusableResourceTest+UnsupportedBuilderConfigurationTest+NetworkBuilderTest ► EnabledCleanUpThrowsException

Failed test found in: Testcontainers.Platform.Linux.Tests.trx Error: Assert.Throws() Failure: Exception type was not an exact match Expected: typeof(System.ArgumentException) Actual: typeof(DotNet.Testcontainers.DockerUnavailableException) ---- DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit: https://dotnet.testcontainers.org/custom_configuration/
Raw output
Assert.Throws() Failure: Exception type was not an exact match
Expected: typeof(System.ArgumentException)
Actual:   typeof(DotNet.Testcontainers.DockerUnavailableException)
---- DotNet.Testcontainers.DockerUnavailableException : Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured.
You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:
https://dotnet.testcontainers.org/custom_configuration/
   at Testcontainers.Tests.ReusableResourceTest.UnsupportedBuilderConfigurationTest.NetworkBuilderTest.EnabledCleanUpThrowsException() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs:line 158
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
----- Inner Stack Trace -----
   at DotNet.Testcontainers.Builders.AbstractBuilder`4.Validate() in /_/src/Testcontainers/Builders/AbstractBuilder`4.cs:line 150
   at DotNet.Testcontainers.Builders.NetworkBuilder.Validate() in /_/src/Testcontainers/Builders/NetworkBuilder.cs:line 84
   at DotNet.Testcontainers.Builders.NetworkBuilder.Build() in /_/src/Testcontainers/Builders/NetworkBuilder.cs:line 71
   at Testcontainers.Tests.ReusableResourceTest.UnsupportedBuilderConfigurationTest.NetworkBuilderTest.<>c__DisplayClass0_0.<EnabledCleanUpThrowsException>b__0() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Platform.Linux.Tests/ReusableResourceTest.cs:line 158
"For more information, visit:\nhttps://dotnet.testcontainers.org/custom_configuration/");
}

const string reuseNotSupported = "Reuse cannot be used in conjunction with WithCleanUp(true).";
_ = Guard.Argument(DockerResourceConfiguration, nameof(IResourceConfiguration<TCreateResourceEntity>.Reuse))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace DotNet.Testcontainers.Builders
using System;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;

Expand All @@ -11,6 +12,9 @@ internal class DockerEndpointAuthenticationProvider : IDockerEndpointAuthenticat
{
private static readonly TaskFactory TaskFactory = new TaskFactory(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default);

[CanBeNull]
public Uri UnavailableEndpoint;

/// <inheritdoc />
public virtual bool IsApplicable()
{
Expand Down Expand Up @@ -42,6 +46,7 @@ await dockerClient.System.PingAsync()
}
catch (Exception)
{
UnavailableEndpoint = dockerClientConfiguration.EndpointBaseUri;
return false;
}
}
Expand Down
35 changes: 19 additions & 16 deletions src/Testcontainers/Configurations/TestcontainersSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,30 @@ namespace DotNet.Testcontainers.Configurations
public static class TestcontainersSettings
{
[CanBeNull]
private static readonly IDockerEndpointAuthenticationProvider DockerEndpointAuthProvider
= new IDockerEndpointAuthenticationProvider[]
{
new TestcontainersEndpointAuthenticationProvider(),
new MTlsEndpointAuthenticationProvider(),
new TlsEndpointAuthenticationProvider(),
new EnvironmentEndpointAuthenticationProvider(),
new NpipeEndpointAuthenticationProvider(),
new UnixEndpointAuthenticationProvider(),
new DockerDesktopEndpointAuthenticationProvider(),
new RootlessUnixEndpointAuthenticationProvider(),
}
.Where(authProvider => authProvider.IsApplicable())
.FirstOrDefault(authProvider => authProvider.IsAvailable());
private static readonly IDockerEndpointAuthenticationProvider DockerEndpointAuthProvider;

[CanBeNull]
private static readonly IDockerEndpointAuthenticationConfiguration DockerEndpointAuthConfig
= DockerEndpointAuthProvider?.GetAuthConfig();
private static readonly IDockerEndpointAuthenticationConfiguration DockerEndpointAuthConfig;

internal static readonly IReadOnlyList<Uri> UnavailableEndpoints;

static TestcontainersSettings()
{
var providers = new IDockerEndpointAuthenticationProvider[]
{
new TestcontainersEndpointAuthenticationProvider(),
new MTlsEndpointAuthenticationProvider(),
new TlsEndpointAuthenticationProvider(),
new EnvironmentEndpointAuthenticationProvider(),
new NpipeEndpointAuthenticationProvider(),
new UnixEndpointAuthenticationProvider(),
new DockerDesktopEndpointAuthenticationProvider(),
new RootlessUnixEndpointAuthenticationProvider(),
};

DockerEndpointAuthProvider = providers.Where(authProvider => authProvider.IsApplicable()).FirstOrDefault(authProvider => authProvider.IsAvailable());
DockerEndpointAuthConfig = DockerEndpointAuthProvider?.GetAuthConfig();
UnavailableEndpoints = providers.OfType<DockerEndpointAuthenticationProvider>().Select(e => e.UnavailableEndpoint).Where(e => e != null).Distinct().ToList();
}

/// <summary>
Expand Down
20 changes: 20 additions & 0 deletions src/Testcontainers/DockerUnavailableException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace DotNet.Testcontainers
{
using System;
using JetBrains.Annotations;

/// <summary>
/// The exception that is thrown when Docker is not available (because it is either not running or misconfigured).
/// </summary>
[PublicAPI]
public sealed class DockerUnavailableException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="DockerUnavailableException"/> class, using the provided message.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
public DockerUnavailableException(string message) : base(message)
{
}
}
}

0 comments on commit 9fccae7

Please sign in to comment.