-
-
Notifications
You must be signed in to change notification settings - Fork 294
/
Copy pathTestcontainersNetworkTest.cs
55 lines (46 loc) · 1.71 KB
/
TestcontainersNetworkTest.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
namespace DotNet.Testcontainers.Tests.Unit
{
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Commons;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Tests.Fixtures;
using Xunit;
public sealed class TestcontainersNetworkTest : IClassFixture<NetworkFixture>, IAsyncLifetime
{
private const string AliasSuffix = "-alias";
private readonly IContainer _testcontainer1;
private readonly IContainer _testcontainer2;
public TestcontainersNetworkTest(NetworkFixture networkFixture)
{
var testcontainersBuilder = new ContainerBuilder()
.WithImage("alpine")
.WithEntrypoint(CommonCommands.SleepInfinity)
.WithNetwork(networkFixture.Network.Name);
_testcontainer1 = testcontainersBuilder
.WithHostname(nameof(_testcontainer1))
.WithNetworkAliases(nameof(_testcontainer1) + AliasSuffix)
.Build();
_testcontainer2 = testcontainersBuilder
.WithHostname(nameof(_testcontainer2))
.WithNetworkAliases(nameof(_testcontainer2) + AliasSuffix)
.Build();
}
public Task InitializeAsync()
{
return Task.WhenAll(_testcontainer1.StartAsync(), _testcontainer2.StartAsync());
}
public Task DisposeAsync()
{
return Task.WhenAll(_testcontainer1.DisposeAsync().AsTask(), _testcontainer2.DisposeAsync().AsTask());
}
[Theory]
[InlineData(nameof(_testcontainer2))]
[InlineData(nameof(_testcontainer2) + AliasSuffix)]
public async Task PingContainer(string destination)
{
var execResult = await _testcontainer1.ExecAsync(new[] { "ping", "-c", "4", destination });
Assert.Equal(0, execResult.ExitCode);
}
}
}