|
| 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