-
Notifications
You must be signed in to change notification settings - Fork 411
Expand file tree
/
Copy pathISwarmOperationsTests.cs
More file actions
74 lines (69 loc) · 2.62 KB
/
ISwarmOperationsTests.cs
File metadata and controls
74 lines (69 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Docker.DotNet.Models;
using System.Collections.Generic;
using Xunit;
using System;
namespace Docker.DotNet.Tests
{
public class ISwarmOperationsTests :IDisposable
{
private readonly DockerClient _client;
private readonly string _testServiceId;
private static string _testServiceName = "docker-dotnet-test-service";
public ISwarmOperationsTests()
{
_client = new DockerClientConfiguration().CreateClient();
_testServiceId = _client.Swarm.CreateServiceAsync(new ServiceCreateParameters()
{
Service = new ServiceSpec
{
Name = _testServiceName,
TaskTemplate = new TaskSpec()
{
ContainerSpec = new ContainerSpec()
{
Image = "nginx:latest"
}
}
}
}).Result.ID;
}
[Fact]
public async Task GetServicesAsync_Succeeds()
{
var services = await _client.Swarm.ListServicesAsync(cancellationToken: CancellationToken.None);
Assert.Contains(_testServiceId, services.Select(s => s.ID));
}
[Fact]
public async Task GetFilteredServicesAsync_Succeeds()
{
var services = await _client.Swarm.ListServicesAsync(new ServicesListParameters { Filters = new ServiceFilter { Name = new string[] { _testServiceName } } }, CancellationToken.None);
Assert.Single(services);
}
[Fact]
public async Task CreateServiceAsync_FaultyNetwork_Throws()
{
await Assert.ThrowsAsync<DockerSwarmException>(() => _client.Swarm.CreateServiceAsync(new ServiceCreateParameters()
{
Service = new ServiceSpec
{
Name = $"{_testServiceName}2",
TaskTemplate = new TaskSpec()
{
ContainerSpec = new ContainerSpec()
{
Image = "nginx:latest"
}
},
Networks = new List<NetworkAttachmentConfig>() { new NetworkAttachmentConfig() { Target = "non-existing-network" } }
}
}));
}
public void Dispose()
{
_client.Swarm.RemoveServiceAsync(_testServiceId, CancellationToken.None);
}
}
}