BUG: DotNet.Testcontainers.Tests.Unit.DockerEndpointAuthenticationProviderTest.GetDockerClientConfiguration is failing
Describe the bug
Unit test DotNet.Testcontainers.Tests.Unit.DockerEndpointAuthenticationProviderTest.GetDockerClientConfiguration is failing when all test are executed. I think it is related to change in file src/Testcontainers/Configurations/EnvironmentConfiguration.cs in PR #550:
/// <summary>
/// Gets the <see cref="ICustomConfiguration" /> instance.
/// </summary>
public static ICustomConfiguration Instance { get; }
= new EnvironmentConfiguration();
and usage in file src/Testcontainers/Builders/EnvironmentEndpointAuthenticationProvider.cs
public EnvironmentEndpointAuthenticationProvider()
{
this.dockerEngine = PropertiesFileConfiguration.Instance.GetDockerHost() ?? EnvironmentConfiguration.Instance.GetDockerHost();
}
To Reproduce Steps to reproduce the behavior:
- There is not testcontainer setting file or empty
- There is not environment variable
DOCKER_HOSTset in the OS - Run all tests (at least one which needs to get DockerClientConfiguration)
-
GetDockerClientConfigurationtest forEnvironmentEndpointAuthenticationProvidertest case fail on errorSystem.ArgumentNullException : Value cannot be null. (Parameter 'endpoint')
Expected behavior Test will pass independently on OS setup and order of test execution.
Screenshots

Desktop (please complete the following information):
- latest develop branch
Additional context
I think what happen is that first test which checks some module alreadz trigger static constructor of EnvironmentConfiguration.cs and data are loaded from OS. When test GetDockerClientConfiguration set environment variable to any value, then it is too late.
When the test is executed alone then it works because static constructor is invoked by the first touch of the class. So current implementation of tha test cases of the test is not correct or the implementation should be more flexible.
Current implementation:
public AuthConfigTestData()
{
const string dockerHost = "tcp://127.0.0.1:2375";
Environment.SetEnvironmentVariable("DOCKER_HOST", dockerHost);
this.Add(new object[] { new EnvironmentEndpointAuthenticationProvider().GetAuthConfig(), new Uri(dockerHost) });
this.Add(new object[] { new NpipeEndpointAuthenticationProvider().GetAuthConfig(), new Uri("npipe://./pipe/docker_engine") });
this.Add(new object[] { new UnixEndpointAuthenticationProvider().GetAuthConfig(), new Uri("unix:/var/run/docker.sock") });
Environment.SetEnvironmentVariable("DOCKER_HOST", null);
}
I found it more problematic when I wanted to extend this test for PR #548 by following code which does not work completly:
public AuthConfigTestData()
{
const string dockerHost = "tcp://127.0.0.1:2375";
const string dockerHostTls = "tcp://127.0.0.1:2376";
Environment.SetEnvironmentVariable("DOCKER_HOST", dockerHostTls);
this.Add(new object[] { new TlsEndpointAuthenticationProvider().GetAuthConfig(), new Uri(dockerHostTls) });
Environment.SetEnvironmentVariable("DOCKER_HOST", dockerHost);
this.Add(new object[] { new EnvironmentEndpointAuthenticationProvider().GetAuthConfig(), new Uri(dockerHost) });
this.Add(new object[] { new NpipeEndpointAuthenticationProvider().GetAuthConfig(), new Uri("npipe://./pipe/docker_engine") });
this.Add(new object[] { new UnixEndpointAuthenticationProvider().GetAuthConfig(), new Uri("unix:/var/run/docker.sock") });
Environment.SetEnvironmentVariable("DOCKER_HOST", null);
}
I would like to ask which way to use as solution. I need to solve it before I will continue on PR #548
I added PR with possible solution #577.