-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathComposeDescriptor.cs
65 lines (52 loc) · 2.73 KB
/
ComposeDescriptor.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
using System.Collections.Generic;
using System.Threading.Tasks;
using ComposeTestEnvironment.xUnit;
// It is necessary to run and tear down docker-compose
[assembly: Xunit.TestFramework("ComposeTestEnvironment.xUnit.TestFramework", "ComposeTestEnvironment.xUnit")]
namespace Sample
{
public class ComposeDescriptor : DockerComposeDescriptor
{
// docker-compose file name (it will try to find it in nearest parent directory)
public override string ComposeFileName => "testcompose.yml";
public override IReadOnlyDictionary<string, int[]> Ports => new Dictionary<string, int[]>
{
// Specify all used in tests default service ports
["sqlserver"] = new[] {1433},
["jaeger"] = new[] { 16686, 5778 }, // Not used in tests, but specified for example
};
// Additional settings
// Change to false to do not tear down docker compose after test execution
public override bool DownOnComplete => true;
public override IReadOnlyList<string> StartedMessageMarkers => new[]
{
// Wait for this message in docker output to detect that SQL Server is started and can accept connection
// as port listening is not enough to detect correctly started server
"has been set for engine and full-text services"
};
// Override to False when you use different mechanisms to detect that all service are up and running
public override bool WaitForPortsListen => true;
// You can skip several ports from service started detection (for example this collection should contain udp only ports)
public override IReadOnlyDictionary<string, int[]> IgnoreWaitForPortListening { get; } = new Dictionary<string, int[]>();
public override Task WaitForReady(Discovery discovery)
{
// You can specify additional logic to detect that all services are up and ready
return Task.CompletedTask;
}
public override async Task<IReadOnlyDictionary<string, string>> GetEnvironment(string serviceName, IReadOnlyDictionary<string, string> existing, Discovery discovery)
{
// You can replace environment variable for specific docker-compose service
// For example it can be useful to setup correct outbound listening port for Kafka
// Example code:
// if (serviceName == "sqlserver")
// {
// return new Dictionary<string, string>
// {
// ["ACCEPT_EULA"] = "Y",
// ["SA_PASSWORD"] = "yourStrong(!)Password",
// };
// }
return await base.GetEnvironment(serviceName, existing, discovery);
}
}
}