Skip to content

Commit

Permalink
Added overload for IVolumeOperations.ListAsync that accepts a Volumes…
Browse files Browse the repository at this point in the history
…ListParameters argument. (#530)
  • Loading branch information
Emdot authored Aug 31, 2021
1 parent 7a19003 commit 2ae4c63
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Docker.DotNet/Endpoints/IVolumeOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ public interface IVolumeOperations
/// </remarks>
Task<VolumesListResponse> ListAsync(CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// List volumes
/// </summary>
/// <remarks>
/// 200 - No error.
/// 500 - Server error.
/// </remarks>
Task<VolumesListResponse> ListAsync(VolumesListParameters parameters, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Create a volume.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Docker.DotNet/Endpoints/VolumeOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ async Task<VolumesListResponse> IVolumeOperations.ListAsync(CancellationToken ca
return this._client.JsonSerializer.DeserializeObject<VolumesListResponse>(response.Body);
}

async Task<VolumesListResponse> IVolumeOperations.ListAsync(VolumesListParameters parameters, CancellationToken cancellationToken)
{
var queryParameters = parameters == null ? null : new QueryString<VolumesListParameters>(parameters);
var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Get, "volumes", queryParameters, null, cancellationToken).ConfigureAwait(false);
return this._client.JsonSerializer.DeserializeObject<VolumesListResponse>(response.Body);
}

async Task<VolumeResponse> IVolumeOperations.CreateAsync(VolumesCreateParameters parameters, CancellationToken cancellationToken)
{
if (parameters == null)
Expand Down
69 changes: 69 additions & 0 deletions test/Docker.DotNet.Tests/IVolumeOperationsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Docker.DotNet.Models;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;

namespace Docker.DotNet.Tests
{
[Collection("Test collection")]
public class IVolumeOperationsTests
{

private readonly CancellationTokenSource _cts;

private readonly TestOutput _output;
private readonly string _repositoryName;
private readonly string _tag = Guid.NewGuid().ToString();
private readonly DockerClientConfiguration _dockerConfiguration;
private readonly DockerClient _dockerClient;

public IVolumeOperationsTests(TestFixture testFixture, ITestOutputHelper _outputHelper)
{
_output = new TestOutput(_outputHelper);

_dockerConfiguration = new DockerClientConfiguration();
_dockerClient = _dockerConfiguration.CreateClient();

// Do not wait forever in case it gets stuck
_cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
_cts.Token.Register(() => throw new TimeoutException("ImageOperationTests timeout"));

_repositoryName = testFixture.repositoryName;
_tag = testFixture.tag;
}

[Fact]
public async Task ListAsync_VolumeExists_Succeeds()
{
const string volumeName = "docker-dotnet-test-volume";

await _dockerClient.Volumes.CreateAsync(new VolumesCreateParameters
{
Name = volumeName,
},
_cts.Token);

try
{

var response = await _dockerClient.Volumes.ListAsync(new VolumesListParameters()
{
Filters = new Dictionary<string, IDictionary<string, bool>>(),
},
_cts.Token);

Assert.Contains(volumeName, response.Volumes.Select(volume => volume.Name));

}
finally
{
await _dockerClient.Volumes.RemoveAsync(volumeName, force: true, _cts.Token);
}
}
}
}

0 comments on commit 2ae4c63

Please sign in to comment.