forked from testcontainers/testcontainers-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaitForContainerOS.cs
More file actions
105 lines (87 loc) · 3.96 KB
/
WaitForContainerOS.cs
File metadata and controls
105 lines (87 loc) · 3.96 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
namespace DotNet.Testcontainers.Configurations
{
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text.RegularExpressions;
/// <inheritdoc cref="IWaitForContainerOS" />
internal abstract class WaitForContainerOS : IWaitForContainerOS
{
private readonly ICollection<WaitStrategy> _waitStrategies = new List<WaitStrategy>();
/// <summary>
/// Initializes a new instance of the <see cref="WaitForContainerOS" /> class.
/// </summary>
protected WaitForContainerOS()
{
_waitStrategies.Add(new WaitStrategy(new UntilContainerIsRunning()));
}
/// <inheritdoc />
public abstract IWaitForContainerOS UntilCommandIsCompleted(params string[] command);
/// <inheritdoc />
public abstract IWaitForContainerOS UntilCommandIsCompleted(string command, Action<IWaitStrategy> waitStrategyModifier = null);
/// <inheritdoc />
public abstract IWaitForContainerOS UntilCommandIsCompleted(IEnumerable<string> command, Action<IWaitStrategy> waitStrategyModifier = null);
/// <inheritdoc />
public abstract IWaitForContainerOS UntilPortIsAvailable(int port, Action<IWaitStrategy> waitStrategyModifier = null);
/// <inheritdoc />
public abstract IWaitForContainerOS UntilInternalTcpPortIsAvailable(int containerPort, Action<IWaitStrategy> waitStrategyModifier = null);
/// <inheritdoc />
public virtual IWaitForContainerOS AddCustomWaitStrategy(IWaitUntil waitUntil, Action<IWaitStrategy> waitStrategyModifier = null)
{
var waitStrategy = new WaitStrategy(waitUntil);
if (waitStrategyModifier != null)
{
waitStrategyModifier(waitStrategy);
}
_waitStrategies.Add(waitStrategy);
return this;
}
/// <inheritdoc />
public IWaitForContainerOS UntilExternalTcpPortIsAvailable(int containerPort, Action<IWaitStrategy> waitStrategyModifier = null)
{
return AddCustomWaitStrategy(new UntilExternalTcpPortIsAvailable(containerPort), waitStrategyModifier);
}
/// <inheritdoc />
public virtual IWaitForContainerOS UntilFileExists(string filePath, FileSystem fileSystem = FileSystem.Host, Action<IWaitStrategy> waitStrategyModifier = null)
{
switch (fileSystem)
{
case FileSystem.Container:
return AddCustomWaitStrategy(new UntilFileExistsInContainer(filePath), waitStrategyModifier);
case FileSystem.Host:
default:
return AddCustomWaitStrategy(new UntilFileExistsOnHost(filePath), waitStrategyModifier);
}
}
/// <inheritdoc />
public IWaitForContainerOS UntilMessageIsLogged(string pattern, Action<IWaitStrategy> waitStrategyModifier = null)
{
return AddCustomWaitStrategy(new UntilMessageIsLogged(pattern), waitStrategyModifier);
}
/// <inheritdoc />
public IWaitForContainerOS UntilMessageIsLogged(Regex pattern, Action<IWaitStrategy> waitStrategyModifier = null)
{
return AddCustomWaitStrategy(new UntilMessageIsLogged(pattern), waitStrategyModifier);
}
/// <inheritdoc />
public virtual IWaitForContainerOS UntilHttpRequestIsSucceeded(Func<HttpWaitStrategy, HttpWaitStrategy> request, Action<IWaitStrategy> waitStrategyModifier = null)
{
return AddCustomWaitStrategy(request.Invoke(new HttpWaitStrategy()), waitStrategyModifier);
}
/// <inheritdoc />
public virtual IWaitForContainerOS UntilContainerIsHealthy(long failingStreak = 3, Action<IWaitStrategy> waitStrategyModifier = null)
{
return AddCustomWaitStrategy(new UntilContainerIsHealthy(failingStreak), waitStrategyModifier);
}
/// <inheritdoc />
public virtual IWaitForContainerOS UntilDatabaseIsAvailable(DbProviderFactory dbProviderFactory, Action<IWaitStrategy> waitStrategyModifier = null)
{
return AddCustomWaitStrategy(new UntilDatabaseIsAvailable(dbProviderFactory), waitStrategyModifier);
}
/// <inheritdoc />
public IEnumerable<WaitStrategy> Build()
{
return _waitStrategies;
}
}
}