forked from testcontainers/testcontainers-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsContainerTest.cs
More file actions
80 lines (70 loc) · 2.71 KB
/
WindowsContainerTest.cs
File metadata and controls
80 lines (70 loc) · 2.71 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
75
76
77
78
79
80
namespace Testcontainers.Tests;
public abstract class WindowsContainerTest : IAsyncLifetime
{
private readonly IContainer _container;
private WindowsContainerTest(IContainer container)
{
_container = container;
}
public async ValueTask InitializeAsync()
{
await _container.StartAsync()
.ConfigureAwait(false);
}
public async ValueTask DisposeAsync()
{
await DisposeAsyncCore()
.ConfigureAwait(false);
GC.SuppressFinalize(this);
}
[SkipOnLinuxEngine]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Windows))]
public void ContainerIsRunning()
{
Assert.Equal(TestcontainersStates.Running, _container.State);
}
protected virtual ValueTask DisposeAsyncCore()
{
return _container.DisposeAsync();
}
[UsedImplicitly]
public sealed class UntilCommandIsCompleted : WindowsContainerTest
{
public UntilCommandIsCompleted()
: base(new ContainerBuilder()
.WithImage(CommonImages.ServerCore)
.WithEntrypoint("PowerShell", "-NoLogo", "-Command")
.WithCommand("Start-Sleep -Seconds 120")
.WithWaitStrategy(Wait.ForWindowsContainer().UntilCommandIsCompleted("Exit(-Not(Test-Path -Path 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'))"))
.Build())
{
}
}
[UsedImplicitly]
public sealed class UntilInternalTcpPortIsAvailable : WindowsContainerTest
{
public UntilInternalTcpPortIsAvailable()
: base(new ContainerBuilder()
.WithImage(CommonImages.ServerCore)
.WithEntrypoint("PowerShell", "-NoLogo", "-Command")
.WithCommand("$tcpListener = [System.Net.Sockets.TcpListener]80; $tcpListener.Start();$client = $tcpListener.AcceptTcpClient(); Start-Sleep -Seconds 120")
.WithWaitStrategy(Wait.ForWindowsContainer().UntilPortIsAvailable(80))
.Build())
{
}
}
[UsedImplicitly]
public sealed class UntilExternalTcpPortIsAvailable : WindowsContainerTest
{
public UntilExternalTcpPortIsAvailable()
: base(new ContainerBuilder()
.WithImage(CommonImages.ServerCore)
.WithPortBinding(80, true)
.WithEntrypoint("PowerShell", "-NoLogo", "-Command")
.WithCommand("$tcpListener = [System.Net.Sockets.TcpListener]80; $tcpListener.Start();$client = $tcpListener.AcceptTcpClient(); Start-Sleep -Seconds 120")
.WithWaitStrategy(Wait.ForWindowsContainer().UntilExternalTcpPortIsAvailable(80))
.Build())
{
}
}
}