Skip to content

Commit 2ae4c63

Browse files
authored
Added overload for IVolumeOperations.ListAsync that accepts a VolumesListParameters argument. (#530)
1 parent 7a19003 commit 2ae4c63

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

src/Docker.DotNet/Endpoints/IVolumeOperations.cs

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ public interface IVolumeOperations
1616
/// </remarks>
1717
Task<VolumesListResponse> ListAsync(CancellationToken cancellationToken = default(CancellationToken));
1818

19+
/// <summary>
20+
/// List volumes
21+
/// </summary>
22+
/// <remarks>
23+
/// 200 - No error.
24+
/// 500 - Server error.
25+
/// </remarks>
26+
Task<VolumesListResponse> ListAsync(VolumesListParameters parameters, CancellationToken cancellationToken = default(CancellationToken));
27+
1928
/// <summary>
2029
/// Create a volume.
2130
/// </summary>

src/Docker.DotNet/Endpoints/VolumeOperations.cs

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ async Task<VolumesListResponse> IVolumeOperations.ListAsync(CancellationToken ca
2222
return this._client.JsonSerializer.DeserializeObject<VolumesListResponse>(response.Body);
2323
}
2424

25+
async Task<VolumesListResponse> IVolumeOperations.ListAsync(VolumesListParameters parameters, CancellationToken cancellationToken)
26+
{
27+
var queryParameters = parameters == null ? null : new QueryString<VolumesListParameters>(parameters);
28+
var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Get, "volumes", queryParameters, null, cancellationToken).ConfigureAwait(false);
29+
return this._client.JsonSerializer.DeserializeObject<VolumesListResponse>(response.Body);
30+
}
31+
2532
async Task<VolumeResponse> IVolumeOperations.CreateAsync(VolumesCreateParameters parameters, CancellationToken cancellationToken)
2633
{
2734
if (parameters == null)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Docker.DotNet.Models;
7+
using Newtonsoft.Json;
8+
using Xunit;
9+
using Xunit.Abstractions;
10+
11+
namespace Docker.DotNet.Tests
12+
{
13+
[Collection("Test collection")]
14+
public class IVolumeOperationsTests
15+
{
16+
17+
private readonly CancellationTokenSource _cts;
18+
19+
private readonly TestOutput _output;
20+
private readonly string _repositoryName;
21+
private readonly string _tag = Guid.NewGuid().ToString();
22+
private readonly DockerClientConfiguration _dockerConfiguration;
23+
private readonly DockerClient _dockerClient;
24+
25+
public IVolumeOperationsTests(TestFixture testFixture, ITestOutputHelper _outputHelper)
26+
{
27+
_output = new TestOutput(_outputHelper);
28+
29+
_dockerConfiguration = new DockerClientConfiguration();
30+
_dockerClient = _dockerConfiguration.CreateClient();
31+
32+
// Do not wait forever in case it gets stuck
33+
_cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
34+
_cts.Token.Register(() => throw new TimeoutException("ImageOperationTests timeout"));
35+
36+
_repositoryName = testFixture.repositoryName;
37+
_tag = testFixture.tag;
38+
}
39+
40+
[Fact]
41+
public async Task ListAsync_VolumeExists_Succeeds()
42+
{
43+
const string volumeName = "docker-dotnet-test-volume";
44+
45+
await _dockerClient.Volumes.CreateAsync(new VolumesCreateParameters
46+
{
47+
Name = volumeName,
48+
},
49+
_cts.Token);
50+
51+
try
52+
{
53+
54+
var response = await _dockerClient.Volumes.ListAsync(new VolumesListParameters()
55+
{
56+
Filters = new Dictionary<string, IDictionary<string, bool>>(),
57+
},
58+
_cts.Token);
59+
60+
Assert.Contains(volumeName, response.Volumes.Select(volume => volume.Name));
61+
62+
}
63+
finally
64+
{
65+
await _dockerClient.Volumes.RemoveAsync(volumeName, force: true, _cts.Token);
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)