Skip to content

Commit 227bfd5

Browse files
committed
rename to standard
add logging test revert unneeded changes more lr fixes
1 parent a915357 commit 227bfd5

File tree

4 files changed

+83
-14
lines changed

4 files changed

+83
-14
lines changed

src/Docker.DotNet/Endpoints/ConfigsOperations.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ internal ConfigsOperations(DockerClient client)
1616
this._client = client;
1717
}
1818

19-
async Task<IList<SwarmConfig>> IConfigsOperations.ListAsync(CancellationToken cancellationToken)
19+
async Task<IList<SwarmConfig>> IConfigsOperations.ListConfigAsync(CancellationToken cancellationToken)
2020
{
2121
var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Get, "configs", cancellationToken).ConfigureAwait(false);
2222
return this._client.JsonSerializer.DeserializeObject<IList<SwarmConfig>>(response.Body);
2323
}
2424

25-
async Task<SwarmCreateConfigResponse> IConfigsOperations.CreateAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken)
25+
async Task<SwarmCreateConfigResponse> IConfigsOperations.CreateConfigAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken)
2626
{
2727
if (body == null)
2828
{
@@ -34,7 +34,7 @@ async Task<SwarmCreateConfigResponse> IConfigsOperations.CreateAsync(SwarmCreate
3434
return this._client.JsonSerializer.DeserializeObject<SwarmCreateConfigResponse>(response.Body);
3535
}
3636

37-
async Task<SwarmConfig> IConfigsOperations.InspectAsync(string id, CancellationToken cancellationToken)
37+
async Task<SwarmConfig> IConfigsOperations.InspectConfigAsync(string id, CancellationToken cancellationToken)
3838
{
3939
if (string.IsNullOrEmpty(id))
4040
{
@@ -45,7 +45,7 @@ async Task<SwarmConfig> IConfigsOperations.InspectAsync(string id, CancellationT
4545
return this._client.JsonSerializer.DeserializeObject<SwarmConfig>(response.Body);
4646
}
4747

48-
Task IConfigsOperations.DeleteAsync(string id, CancellationToken cancellationToken)
48+
Task IConfigsOperations.RemoveConfigAsync(string id, CancellationToken cancellationToken)
4949
{
5050
if (string.IsNullOrEmpty(id))
5151
{

src/Docker.DotNet/Endpoints/IConfigsOperations.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ namespace Docker.DotNet
88
public interface IConfigsOperations
99
{
1010
/// <summary>
11-
/// List secrets
11+
/// List configs
1212
/// </summary>
1313
/// <remarks>
1414
/// 200 - No error.
1515
/// 500 - Server error.
1616
/// </remarks>
17-
Task<IList<SwarmConfig>> ListAsync(CancellationToken cancellationToken = default(CancellationToken));
17+
Task<IList<SwarmConfig>> ListConfigAsync(CancellationToken cancellationToken = default(CancellationToken));
1818

1919
/// <summary>
20-
/// Create a secret
20+
/// Create a configs
2121
/// </summary>
2222
/// <remarks>
2323
/// 201 - No error.
2424
/// 406 - Server error or node is not part of a swarm.
2525
/// 409 - Name conflicts with an existing object.
2626
/// 500 - Server error.
2727
/// </remarks>
28-
Task<SwarmCreateConfigResponse> CreateAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken = default(CancellationToken));
28+
Task<SwarmCreateConfigResponse> CreateConfigAsync(SwarmCreateConfigParameters body, CancellationToken cancellationToken = default(CancellationToken));
2929

3030
/// <summary>
31-
/// Inspect a secret
31+
/// Inspect a configs
3232
/// </summary>
3333
/// <remarks>
3434
/// 200 - No error.
@@ -37,17 +37,17 @@ public interface IConfigsOperations
3737
/// 500 - Server error.
3838
/// </remarks>
3939
/// <param name="id">ID of the config.</param>
40-
Task<SwarmConfig> InspectAsync(string id, CancellationToken cancellationToken = default(CancellationToken));
40+
Task<SwarmConfig> InspectConfigAsync(string id, CancellationToken cancellationToken = default(CancellationToken));
4141

4242
/// <summary>
43-
/// Delete a secret
43+
/// Remove a configs
4444
/// </summary>
4545
/// <remarks>
4646
/// 204 - No error.
4747
/// 404 - Secret not found.
4848
/// 500 - Server error.
4949
/// </remarks>
5050
/// <param name="id">ID of the config.</param>
51-
Task DeleteAsync(string id, CancellationToken cancellationToken = default(CancellationToken));
51+
Task RemoveConfigAsync(string id, CancellationToken cancellationToken = default(CancellationToken));
5252
}
5353
}

src/Docker.DotNet/Endpoints/SwarmOperations.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ async Task<ServiceUpdateResponse> ISwarmOperations.UpdateServiceAsync(string id,
192192
return new MultiplexedStream(result, !tty);
193193
}
194194

195-
async Task ISwarmOperations.UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken)
195+
async Task ISwarmOperations.UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken)
196196
{
197197
var query = new QueryString<SwarmUpdateParameters>(parameters ?? throw new ArgumentNullException(nameof(parameters)));
198198
var body = new JsonRequestContent<Spec>(parameters.Spec ?? throw new ArgumentNullException(nameof(parameters.Spec)), this._client.JsonSerializer);
@@ -247,7 +247,7 @@ async Task<NodeListResponse> ISwarmOperations.InspectNodeAsync(string id, Cancel
247247
async Task ISwarmOperations.RemoveNodeAsync(string id, bool force, CancellationToken cancellationToken)
248248
{
249249
if (string.IsNullOrEmpty(id)) throw new ArgumentNullException(nameof(id));
250-
var parameters = new NodeRemoveParameters {Force = force};
250+
var parameters = new NodeRemoveParameters { Force = force };
251251
var query = new QueryString<NodeRemoveParameters>(parameters);
252252
await this._client.MakeRequestAsync(new[] { SwarmResponseHandler }, HttpMethod.Delete, $"nodes/{id}", query, cancellationToken).ConfigureAwait(false);
253253
}

test/Docker.DotNet.Tests/ISwarmOperationsTests.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
4+
using System.Text;
35
using System.Threading;
46
using System.Threading.Tasks;
57
using Docker.DotNet.Models;
@@ -10,11 +12,18 @@ namespace Docker.DotNet.Tests
1012
[Collection(nameof(TestCollection))]
1113
public class ISwarmOperationsTests
1214
{
15+
private readonly CancellationTokenSource _cts;
16+
1317
private readonly DockerClient _dockerClient;
1418
private readonly string _imageId;
1519

1620
public ISwarmOperationsTests(TestFixture testFixture)
1721
{
22+
// Do not wait forever in case it gets stuck
23+
_cts = CancellationTokenSource.CreateLinkedTokenSource(testFixture.Cts.Token);
24+
_cts.CancelAfter(TimeSpan.FromMinutes(5));
25+
_cts.Token.Register(() => throw new TimeoutException("SwarmOperationTests timeout"));
26+
1827
_dockerClient = testFixture.DockerClient;
1928
_imageId = testFixture.Image.ID;
2029
}
@@ -148,5 +157,65 @@ public async Task GetServices_Succeeds()
148157
await _dockerClient.Swarm.RemoveServiceAsync(secondServiceId, default);
149158
await _dockerClient.Swarm.RemoveServiceAsync(thirdServiceid, default);
150159
}
160+
161+
[Fact]
162+
public async Task GetServiceLogs_Succeeds()
163+
{
164+
using var cts = CancellationTokenSource.CreateLinkedTokenSource(_cts.Token);
165+
166+
var serviceName = $"service-withLogs-{Guid.NewGuid().ToString().Substring(1, 10)}";
167+
var serviceId = _dockerClient.Swarm.CreateServiceAsync(new ServiceCreateParameters
168+
{
169+
Service = new ServiceSpec
170+
{
171+
Name = serviceName,
172+
TaskTemplate = new TaskSpec { ContainerSpec = new ContainerSpec { Image = _imageId } }
173+
}
174+
}).Result.ID;
175+
176+
var _stream = await _dockerClient.Swarm.GetServiceLogsAsync(serviceName, false, new ServiceLogsParameters
177+
{
178+
Follow = true,
179+
ShowStdout = true,
180+
ShowStderr = true
181+
});
182+
183+
TimeSpan delay = TimeSpan.FromSeconds(10);
184+
cts.CancelAfter(delay);
185+
186+
var logLines = new List<string>();
187+
while (!cts.IsCancellationRequested)
188+
{
189+
var line = new List<byte>();
190+
var buffer = new byte[1];
191+
192+
while (!cts.IsCancellationRequested)
193+
{
194+
var res = await _stream.ReadOutputAsync(buffer, 0, 1, default);
195+
196+
if (res.Count == 0)
197+
{
198+
continue;
199+
}
200+
201+
else if (buffer[0] == '\n')
202+
{
203+
break;
204+
}
205+
206+
else
207+
{
208+
line.Add(buffer[0]);
209+
}
210+
}
211+
212+
logLines.Add(Encoding.UTF8.GetString(line.ToArray()));
213+
}
214+
215+
Assert.True(logLines.Any());
216+
Assert.Contains("[INF]", logLines.First());
217+
218+
await _dockerClient.Swarm.RemoveServiceAsync(serviceId, default);
219+
}
151220
}
152221
}

0 commit comments

Comments
 (0)