Skip to content

Commit 2b86300

Browse files
committed
test both clients types
1 parent 4146af1 commit 2b86300

File tree

9 files changed

+330
-234
lines changed

9 files changed

+330
-234
lines changed

src/Docker.DotNet/DockerClient.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ internal DockerClient(DockerClientConfiguration configuration, Version requested
4444
throw new Exception("TLS not supported over npipe");
4545
}
4646

47+
if (Configuration.NativeHttpHandler)
48+
{
49+
throw new Exception("Npipe not supported with native handler");
50+
}
51+
4752
var segments = uri.Segments;
4853
if (segments.Length != 3 || !segments[1].Equals("pipe/", StringComparison.OrdinalIgnoreCase))
4954
{
@@ -77,23 +82,36 @@ await stream.ConnectAsync(timeout, cancellationToken)
7782
case "http":
7883
var builder = new UriBuilder(uri)
7984
{
80-
Scheme = configuration.Credentials.IsTlsCredentials() ? "https" : "http"
85+
Scheme = Configuration.Credentials.IsTlsCredentials() ? "https" : "http"
8186
};
8287
uri = builder.Uri;
83-
if (configuration.NativeHttpHandler)
88+
if (Configuration.NativeHttpHandler)
89+
{
8490
handler = new HttpClientHandler();
91+
}
8592
else
93+
{
8694
handler = new ManagedHandler(logger);
95+
}
8796
break;
8897

8998
case "https":
90-
if (configuration.NativeHttpHandler)
99+
if (Configuration.NativeHttpHandler)
100+
{
91101
handler = new HttpClientHandler();
102+
}
92103
else
104+
{
93105
handler = new ManagedHandler(logger);
106+
}
94107
break;
95108

96109
case "unix":
110+
if (Configuration.NativeHttpHandler)
111+
{
112+
throw new Exception("Unix sockets not supported with native handler");
113+
}
114+
97115
var pipeString = uri.LocalPath;
98116
handler = new ManagedHandler(async (host, port, cancellationToken) =>
99117
{
@@ -108,7 +126,7 @@ await sock.ConnectAsync(new Microsoft.Net.Http.Client.UnixDomainSocketEndPoint(p
108126
break;
109127

110128
default:
111-
throw new Exception($"Unknown URL scheme {configuration.EndpointBaseUri.Scheme}");
129+
throw new Exception($"Unknown URL scheme {Configuration.EndpointBaseUri.Scheme}");
112130
}
113131

114132
_endpointBaseUri = uri;

test/Docker.DotNet.Tests/IConfigOperationsTests.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ public IConfigOperationsTests(TestFixture testFixture, ITestOutputHelper testOut
1212
_testOutputHelper = testOutputHelper;
1313
}
1414

15-
[Fact]
16-
public async Task SwarmConfig_CanCreateAndRead()
15+
public static IEnumerable<object[]> GetDockerClientTypes() =>
16+
Enum.GetValues(typeof(DockerClientType))
17+
.Cast<DockerClientType>()
18+
.Select(t => new object[] { t });
19+
20+
[Theory]
21+
[MemberData(nameof(GetDockerClientTypes))]
22+
public async Task SwarmConfig_CanCreateAndRead(DockerClientType clientType)
1723
{
18-
var currentConfigs = await _testFixture.DockerClient.Configs.ListConfigsAsync();
24+
var currentConfigs = await _testFixture.DockerClients[clientType].Configs.ListConfigsAsync();
1925

2026
_testOutputHelper.WriteLine($"Current Configs: {currentConfigs.Count}");
2127

@@ -31,15 +37,15 @@ public async Task SwarmConfig_CanCreateAndRead()
3137
Config = testConfigSpec
3238
};
3339

34-
var createdConfig = await _testFixture.DockerClient.Configs.CreateConfigAsync(configParameters);
40+
var createdConfig = await _testFixture.DockerClients[clientType].Configs.CreateConfigAsync(configParameters);
3541
Assert.NotNull(createdConfig.ID);
3642
_testOutputHelper.WriteLine($"Config created: {createdConfig.ID}");
3743

38-
var configs = await _testFixture.DockerClient.Configs.ListConfigsAsync();
44+
var configs = await _testFixture.DockerClients[clientType].Configs.ListConfigsAsync();
3945
Assert.Contains(configs, c => c.ID == createdConfig.ID);
4046
_testOutputHelper.WriteLine($"Current Configs: {configs.Count}");
4147

42-
var configResponse = await _testFixture.DockerClient.Configs.InspectConfigAsync(createdConfig.ID);
48+
var configResponse = await _testFixture.DockerClients[clientType].Configs.InspectConfigAsync(createdConfig.ID);
4349

4450
Assert.NotNull(configResponse);
4551

@@ -51,8 +57,8 @@ public async Task SwarmConfig_CanCreateAndRead()
5157

5258
_testOutputHelper.WriteLine("Config created is the same.");
5359

54-
await _testFixture.DockerClient.Configs.RemoveConfigAsync(createdConfig.ID);
60+
await _testFixture.DockerClients[clientType].Configs.RemoveConfigAsync(createdConfig.ID);
5561

56-
await Assert.ThrowsAsync<DockerApiException>(() => _testFixture.DockerClient.Configs.InspectConfigAsync(createdConfig.ID));
62+
await Assert.ThrowsAsync<DockerApiException>(() => _testFixture.DockerClients[clientType].Configs.InspectConfigAsync(createdConfig.ID));
5763
}
5864
}

0 commit comments

Comments
 (0)