forked from sshnet/SSH.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfrastructureFixture.cs
More file actions
83 lines (65 loc) · 2.54 KB
/
InfrastructureFixture.cs
File metadata and controls
83 lines (65 loc) · 2.54 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
81
82
83
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Images;
namespace Renci.SshNet.IntegrationTests.TestsFixtures
{
public sealed class InfrastructureFixture : IDisposable
{
private InfrastructureFixture()
{
}
private static readonly Lazy<InfrastructureFixture> InstanceLazy = new Lazy<InfrastructureFixture>(() => new InfrastructureFixture());
public static InfrastructureFixture Instance
{
get
{
return InstanceLazy.Value;
}
}
private IContainer _sshServer;
private IFutureDockerImage _sshServerImage;
public string SshServerHostName { get; set; }
public ushort SshServerPort { get; set; }
public SshUser AdminUser = new SshUser("sshnetadm", "ssh4ever");
public SshUser User = new SshUser("sshnet", "ssh4ever");
public async Task InitializeAsync()
{
_sshServerImage = new ImageFromDockerfileBuilder()
.WithName("renci-ssh-tests-server-image")
.WithDockerfileDirectory(CommonDirectoryPath.GetSolutionDirectory(), Path.Combine("test", "Renci.SshNet.IntegrationTests"))
.WithDockerfile("Dockerfile.TestServer")
.WithDeleteIfExists(true)
.Build();
await _sshServerImage.CreateAsync();
_sshServer = new ContainerBuilder()
.WithHostname("renci-ssh-tests-server")
.WithImage(_sshServerImage)
.WithPortBinding(22, true)
.Build();
await _sshServer.StartAsync();
SshServerPort = _sshServer.GetMappedPublicPort(22);
SshServerHostName = _sshServer.Hostname;
// Socket fails on Linux, reporting inability early. This is the Linux behavior by design.
// https://github.com/dotnet/runtime/issues/47484#issuecomment-769239699
// At this point we have to wait until the ssh server in the container is available
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
await Task.Delay(300);
}
}
public async Task DisposeAsync()
{
if (_sshServer != null)
{
await _sshServer.DisposeAsync();
}
if (_sshServerImage != null)
{
await _sshServerImage.DisposeAsync();
}
}
public void Dispose()
{
}
}
}