Try to set Docker endpoint correctly for TLS
This commit is contained in:
parent
0e086b3b6c
commit
679c2c9af3
5 changed files with 67 additions and 3 deletions
|
@ -18,6 +18,9 @@ test:
|
||||||
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/docker
|
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/docker
|
||||||
script:
|
script:
|
||||||
- curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.4.tgz | tar -xzv -C /usr/local/
|
- curl https://download.docker.com/linux/static/stable/x86_64/docker-20.10.4.tgz | tar -xzv -C /usr/local/
|
||||||
|
- mkdir /usr/local/share/ca-certificates/docker-ca
|
||||||
|
- cp "${DOCKER_CERT_PATH}/ca.pem" /usr/local/share/ca-certificates/docker-ca/
|
||||||
|
- update-ca-certificates --fresh
|
||||||
- dotnet tool restore
|
- dotnet tool restore
|
||||||
- dotnet nuke Test
|
- dotnet nuke Test
|
||||||
|
|
||||||
|
|
36
tests/INetMock.Client.IntegrationTest/DockerEndpoint.cs
Normal file
36
tests/INetMock.Client.IntegrationTest/DockerEndpoint.cs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace INetMock.Client.IntegrationTest
|
||||||
|
{
|
||||||
|
internal static class DockerEndpoint
|
||||||
|
{
|
||||||
|
private const string DockerHostEnvName = "DOCKER_HOST";
|
||||||
|
private const string DockerTlsVerifyEnvName = "DOCKER_TLS_VERIFY";
|
||||||
|
|
||||||
|
internal static string DetermineFromEnv() => DetermineEndpoint(
|
||||||
|
Environment.GetEnvironmentVariable(DockerHostEnvName),
|
||||||
|
Environment.GetEnvironmentVariable(DockerTlsVerifyEnvName)
|
||||||
|
);
|
||||||
|
|
||||||
|
internal static string DetermineEndpoint(string? dockerHost, string? tlsVerify)
|
||||||
|
{
|
||||||
|
dockerHost ??= "";
|
||||||
|
var dockerTlsVerify = int.TryParse(tlsVerify, out var verify) && verify == 1;
|
||||||
|
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||||
|
return (dockerHost, dockerTlsVerify, isWindows) switch
|
||||||
|
{
|
||||||
|
("", _, true) => "npipe://./pipe/docker_engine",
|
||||||
|
("", _, false) => "unix:/var/run/docker.sock",
|
||||||
|
(_, false, _) => dockerHost,
|
||||||
|
(var h, true, _) when h.StartsWith("tcp") => h.Replace(
|
||||||
|
"tcp",
|
||||||
|
"https",
|
||||||
|
true,
|
||||||
|
CultureInfo.InvariantCulture),
|
||||||
|
_ => "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
tests/INetMock.Client.IntegrationTest/DockerEndpointTests.cs
Normal file
22
tests/INetMock.Client.IntegrationTest/DockerEndpointTests.cs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace INetMock.Client.IntegrationTest
|
||||||
|
{
|
||||||
|
public class DockerEndpointTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData(null, null, "unix:/var/run/docker.sock")]
|
||||||
|
[InlineData("tcp://docker:2375", null, "tcp://docker:2375")]
|
||||||
|
[InlineData("tcp://docker:2375", "0", "tcp://docker:2375")]
|
||||||
|
[InlineData("http://docker:2375", null, "http://docker:2375")]
|
||||||
|
[InlineData("http://docker:2375", "0", "http://docker:2375")]
|
||||||
|
[InlineData("tcp://docker:2376", "1", "https://docker:2376")]
|
||||||
|
[InlineData("https://docker:2376", "0", "https://docker:2376")]
|
||||||
|
public void DetermineDockerEndpoint_Input_ExpectedOutput(string? dockerHost, string? tlsVerify, string expected)
|
||||||
|
{
|
||||||
|
var actual = DockerEndpoint.DetermineEndpoint(dockerHost, tlsVerify);
|
||||||
|
|
||||||
|
Assert.Equal(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,8 @@
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
|
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace INetMock.Client.IntegrationTest
|
||||||
{
|
{
|
||||||
public class INetMockServerFixture : IAsyncLifetime
|
public class INetMockServerFixture : IAsyncLifetime
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly TestcontainersContainer _inetmockContainer;
|
private readonly TestcontainersContainer _inetmockContainer;
|
||||||
|
|
||||||
public INetMockServerFixture()
|
public INetMockServerFixture()
|
||||||
|
@ -19,7 +20,7 @@ namespace INetMock.Client.IntegrationTest
|
||||||
.WithCommand("serve")
|
.WithCommand("serve")
|
||||||
.WithPortBinding(80, true)
|
.WithPortBinding(80, true)
|
||||||
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(80))
|
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(80))
|
||||||
.WithDockerEndpoint(Environment.GetEnvironmentVariable("DOCKER_HOST") ?? "unix:///var/run/docker.sock")
|
.WithDockerEndpoint(DockerEndpoint.DetermineFromEnv())
|
||||||
.WithMount(Path.GetTempPath(), "/var/run/inetmock")
|
.WithMount(Path.GetTempPath(), "/var/run/inetmock")
|
||||||
.WithCleanUp(true)
|
.WithCleanUp(true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
Loading…
Reference in a new issue