-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathDependsOnTest.cs
72 lines (56 loc) · 2.51 KB
/
DependsOnTest.cs
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
namespace Testcontainers.Tests;
public sealed class DependsOnTest : IAsyncLifetime
{
private const string DependsOnKey = "org.testcontainers.depends-on";
private const string DependsOnValue = "true";
private readonly IContainer _container = new ContainerBuilder()
.DependsOn(new ContainerBuilder()
.WithImage(CommonImages.Alpine)
.WithLabel(DependsOnKey, DependsOnValue)
.Build())
.DependsOn(new ContainerBuilder()
.WithImage(CommonImages.Alpine)
.WithLabel(DependsOnKey, DependsOnValue)
.Build())
.DependsOn(new NetworkBuilder()
.WithLabel(DependsOnKey, DependsOnValue)
.Build())
.DependsOn(new VolumeBuilder()
.WithLabel(DependsOnKey, DependsOnValue)
.Build(), "/workdir")
.WithImage(CommonImages.Alpine)
.WithLabel(DependsOnKey, DependsOnValue)
.Build();
public Task InitializeAsync()
{
return _container.StartAsync();
}
public Task DisposeAsync()
{
return _container.DisposeAsync().AsTask();
}
[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task DependsOnCreatesDependentResources()
{
// Given
using var clientConfiguration = TestcontainersSettings.OS.DockerEndpointAuthConfig.GetDockerClientConfiguration(ResourceReaper.DefaultSessionId);
using var client = clientConfiguration.CreateClient();
var labelFilter = new Dictionary<string, bool> { { string.Join("=", DependsOnKey, DependsOnValue), true } };
var filters = new Dictionary<string, IDictionary<string, bool>> { { "label", labelFilter } };
var containersListParameters = new ContainersListParameters { All = true, Filters = filters };
var networksListParameters = new NetworksListParameters { Filters = filters };
var volumesListParameters = new VolumesListParameters { Filters = filters };
// When
var containers = await client.Containers.ListContainersAsync(containersListParameters)
.ConfigureAwait(true);
var networks = await client.Networks.ListNetworksAsync(networksListParameters)
.ConfigureAwait(true);
var volumesListResponse = await client.Volumes.ListAsync(volumesListParameters)
.ConfigureAwait(true);
// Then
Assert.Equal(3, containers.Count);
Assert.Single(networks);
Assert.Single(volumesListResponse.Volumes);
}
}