forked from testcontainers/testcontainers-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIWaitForContainerOS.cs
More file actions
136 lines (124 loc) · 6.92 KB
/
IWaitForContainerOS.cs
File metadata and controls
136 lines (124 loc) · 6.92 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
namespace DotNet.Testcontainers.Configurations
{
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text.RegularExpressions;
using DotNet.Testcontainers.Containers;
using JetBrains.Annotations;
/// <summary>
/// Collection of pre-configured strategies to wait until the container is up and running.
/// </summary>
[PublicAPI]
public interface IWaitForContainerOS
{
/// <summary>
/// Adds a custom wait strategy to the wait strategies collection.
/// </summary>
/// <param name="waitUntil">The wait strategy until the container is ready.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
/// <remarks>Already contains <see cref="UntilContainerIsRunning" /> as default wait strategy.</remarks>
[PublicAPI]
IWaitForContainerOS AddCustomWaitStrategy(IWaitUntil waitUntil, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Waits until the command is completed successfully.
/// </summary>
/// <param name="command">The command to be executed.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
/// <remarks>
/// Does not invoke the operating system command shell.
/// Normal shell processing does not happen. Expects the exit code to be 0.
/// </remarks>
[PublicAPI]
IWaitForContainerOS UntilCommandIsCompleted(params string[] command);
/// <summary>
/// Waits until the command is completed successfully.
/// </summary>
/// <param name="command">The command to be executed.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
/// <remarks>Invokes the operating system command shell. Expects the exit code to be 0.</remarks>
[PublicAPI]
IWaitForContainerOS UntilCommandIsCompleted(string command, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Waits until the command is completed successfully.
/// </summary>
/// <param name="command">The command to be executed.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
/// <remarks>
/// Does not invoke the operating system command shell.
/// Normal shell processing does not happen. Expects the exit code to be 0.
/// </remarks>
[PublicAPI]
IWaitForContainerOS UntilCommandIsCompleted(IEnumerable<string> command, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Waits until the port is available.
/// </summary>
/// <param name="port">The port to be checked.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
[PublicAPI]
IWaitForContainerOS UntilPortIsAvailable(int port, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Waits until the file exists.
/// </summary>
/// <param name="filePath">The file path to be checked.</param>
/// <param name="fileSystem">The file system to be checked.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
[PublicAPI]
IWaitForContainerOS UntilFileExists(string filePath, FileSystem fileSystem = FileSystem.Host, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Waits until the message is logged.
/// </summary>
/// <param name="pattern">The regular expression that matches the log message.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
[PublicAPI]
IWaitForContainerOS UntilMessageIsLogged(string pattern, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Waits until the message is logged.
/// </summary>
/// <param name="pattern">The regular expression that matches the log message.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
[PublicAPI]
IWaitForContainerOS UntilMessageIsLogged(Regex pattern, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Waits until the http request is completed successfully.
/// </summary>
/// <param name="request">The http request to be executed.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
[PublicAPI]
IWaitForContainerOS UntilHttpRequestIsSucceeded(Func<HttpWaitStrategy, HttpWaitStrategy> request, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Waits until the container is healthy.
/// </summary>
/// <param name="failingStreak">The number of attempts before an exception is thrown.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
/// <exception cref="TimeoutException">Thrown when number of failed operations exceeded <paramref name="failingStreak" />.</exception>
[PublicAPI]
IWaitForContainerOS UntilContainerIsHealthy(long failingStreak = 3, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Waits until a connection to the database can be successfully opened.
/// </summary>
/// <param name="dbProviderFactory">The <see cref="DbProviderFactory" /> used to create the database connection.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
/// <remarks>
/// This wait strategy must only be applied to containers implementing the <see cref="IDatabaseContainer"/> interface.
/// </remarks>
[PublicAPI]
IWaitForContainerOS UntilDatabaseIsAvailable(DbProviderFactory dbProviderFactory, Action<IWaitStrategy> waitStrategyModifier = null);
/// <summary>
/// Returns a collection with all configured wait strategies.
/// </summary>
/// <returns>Returns a list with all configured wait strategies.</returns>
[PublicAPI]
IEnumerable<WaitStrategy> Build();
}
}