Skip to content

Commit e2a0ac6

Browse files
committed
whitespace
1 parent 61de9c7 commit e2a0ac6

File tree

1 file changed

+75
-75
lines changed

1 file changed

+75
-75
lines changed

test/Docker.Testify/DockerSetup.cs

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -13,91 +13,91 @@
1313

1414
namespace Docker.Testify
1515
{
16-
public abstract class DockerSetup : IDisposable
17-
{
18-
public abstract string ImageName { get; }
19-
public virtual string ContainerPrefix => "tests";
16+
public abstract class DockerSetup : IDisposable
17+
{
18+
public abstract string ImageName { get; }
19+
public virtual string ContainerPrefix => "tests";
2020
public abstract int InternalPort { get; }
2121

2222
public virtual string ImageTag => "latest";
2323
public virtual TimeSpan TimeOut => TimeSpan.FromSeconds(30);
2424
public virtual IList<string> EnvironmentVariables => new List<string>();
25-
public int ExternalPort { get; }
25+
public int ExternalPort { get; }
2626

27-
public abstract bool TestReady();
27+
public abstract bool TestReady();
2828
public abstract void PublishConnectionInfo();
2929

3030
protected readonly DockerClient docker;
31-
protected string containerId;
31+
protected string containerId;
3232

33-
protected DockerSetup()
34-
{
33+
protected DockerSetup()
34+
{
3535
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
36-
docker = new DockerClientConfiguration(new Uri("npipe://./pipe/docker_engine")).CreateClient();
37-
else
38-
docker = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock")).CreateClient();
36+
docker = new DockerClientConfiguration(new Uri("npipe://./pipe/docker_engine")).CreateClient();
37+
else
38+
docker = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock")).CreateClient();
3939

40-
ExternalPort = GetFreePort();
40+
ExternalPort = GetFreePort();
4141

42-
Debug.WriteLine($"Selected port {ExternalPort}");
42+
Debug.WriteLine($"Selected port {ExternalPort}");
4343

4444
StartContainer().Wait();
45-
}
45+
}
4646

47-
public async Task StartContainer()
48-
{
49-
var hostCfg = new HostConfig();
50-
var pb = new PortBinding
51-
{
52-
HostIP = "0.0.0.0",
53-
HostPort = ExternalPort.ToString()
54-
};
47+
public async Task StartContainer()
48+
{
49+
var hostCfg = new HostConfig();
50+
var pb = new PortBinding
51+
{
52+
HostIP = "0.0.0.0",
53+
HostPort = ExternalPort.ToString()
54+
};
5555

56-
hostCfg.PortBindings = new Dictionary<string, IList<PortBinding>>();
57-
hostCfg.PortBindings.Add($"{InternalPort}/tcp", new PortBinding[] { pb });
56+
hostCfg.PortBindings = new Dictionary<string, IList<PortBinding>>();
57+
hostCfg.PortBindings.Add($"{InternalPort}/tcp", new PortBinding[] { pb });
5858

5959
await PullImage(ImageName, ImageTag);
6060

6161
var container = await docker.Containers.CreateContainerAsync(new CreateContainerParameters()
62-
{
63-
Image = $"{ImageName}:{ImageTag}",
64-
Name = $"{ContainerPrefix}-{Guid.NewGuid()}",
65-
HostConfig = hostCfg,
66-
Env = EnvironmentVariables
67-
});
68-
69-
Debug.WriteLine("Starting docker container...");
70-
var started = await docker.Containers.StartContainerAsync(container.ID, new ContainerStartParameters());
71-
if (started)
72-
{
73-
containerId = container.ID;
74-
PublishConnectionInfo();
62+
{
63+
Image = $"{ImageName}:{ImageTag}",
64+
Name = $"{ContainerPrefix}-{Guid.NewGuid()}",
65+
HostConfig = hostCfg,
66+
Env = EnvironmentVariables
67+
});
68+
69+
Debug.WriteLine("Starting docker container...");
70+
var started = await docker.Containers.StartContainerAsync(container.ID, new ContainerStartParameters());
71+
if (started)
72+
{
73+
containerId = container.ID;
74+
PublishConnectionInfo();
7575

7676
Debug.WriteLine("Waiting service to start in the docker container...");
7777

78-
var ready = false;
79-
var expiryTime = DateTime.Now.Add(TimeOut);
78+
var ready = false;
79+
var expiryTime = DateTime.Now.Add(TimeOut);
8080

81-
while ((DateTime.Now < expiryTime) && (!ready))
82-
{
83-
await Task.Delay(1000);
84-
ready = TestReady();
85-
}
81+
while ((DateTime.Now < expiryTime) && (!ready))
82+
{
83+
await Task.Delay(1000);
84+
ready = TestReady();
85+
}
8686

8787
if (ready)
88-
{
89-
Debug.WriteLine($"Docker container started: {container.ID}");
90-
}
91-
else
92-
{
93-
Debug.WriteLine("Docker container timeout waiting for service");
94-
throw new TimeoutException();
95-
}
96-
}
97-
else
98-
{
99-
Debug.WriteLine("Docker container failed");
100-
}
88+
{
89+
Debug.WriteLine($"Docker container started: {container.ID}");
90+
}
91+
else
92+
{
93+
Debug.WriteLine("Docker container timeout waiting for service");
94+
throw new TimeoutException();
95+
}
96+
}
97+
else
98+
{
99+
Debug.WriteLine("Docker container failed");
100+
}
101101
}
102102

103103
public async Task PullImage(string name, string tag)
@@ -119,27 +119,27 @@ public async Task PullImage(string name, string tag)
119119
}
120120
}
121121

122-
public void Dispose()
123-
{
124-
docker.Containers.KillContainerAsync(containerId, new ContainerKillParameters()).Wait();
125-
docker.Containers.RemoveContainerAsync(containerId, new ContainerRemoveParameters() { Force = true }).Wait();
126-
}
122+
public void Dispose()
123+
{
124+
docker.Containers.KillContainerAsync(containerId, new ContainerKillParameters()).Wait();
125+
docker.Containers.RemoveContainerAsync(containerId, new ContainerRemoveParameters() { Force = true }).Wait();
126+
}
127127

128-
private int GetFreePort()
129-
{
130-
const int startRange = 1000;
131-
const int endRange = 10000;
132-
var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
133-
var tcpPorts = ipGlobalProperties.GetActiveTcpListeners();
134-
var udpPorts = ipGlobalProperties.GetActiveUdpListeners();
128+
private int GetFreePort()
129+
{
130+
const int startRange = 1000;
131+
const int endRange = 10000;
132+
var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
133+
var tcpPorts = ipGlobalProperties.GetActiveTcpListeners();
134+
var udpPorts = ipGlobalProperties.GetActiveUdpListeners();
135135

136-
var result = startRange;
136+
var result = startRange;
137137

138-
while (((tcpPorts.Any(x => x.Port == result)) || (udpPorts.Any(x => x.Port == result))) && result <= endRange)
139-
result++;
138+
while (((tcpPorts.Any(x => x.Port == result)) || (udpPorts.Any(x => x.Port == result))) && result <= endRange)
139+
result++;
140140

141-
if (result > endRange)
142-
throw new PortsInUseException();
141+
if (result > endRange)
142+
throw new PortsInUseException();
143143

144144
return result;
145145
}

0 commit comments

Comments
 (0)