-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathIContainer.cs
240 lines (209 loc) · 8.69 KB
/
IContainer.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
namespace DotNet.Testcontainers.Containers
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Images;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
/// <summary>
/// A container instance.
/// </summary>
[PublicAPI]
public interface IContainer : IAsyncDisposable
{
/// <summary>
/// Subscribes to the creating event.
/// </summary>
[CanBeNull]
event EventHandler Creating;
/// <summary>
/// Subscribes to the starting event.
/// </summary>
[CanBeNull]
event EventHandler Starting;
/// <summary>
/// Subscribes to the stopping event.
/// </summary>
[CanBeNull]
event EventHandler Stopping;
/// <summary>
/// Subscribes to the created event.
/// </summary>
[CanBeNull]
event EventHandler Created;
/// <summary>
/// Subscribes to the started event.
/// </summary>
[CanBeNull]
event EventHandler Started;
/// <summary>
/// Subscribes to the stopped event.
/// </summary>
[CanBeNull]
event EventHandler Stopped;
/// <summary>
/// Gets the created timestamp.
/// </summary>
DateTime CreatedTime { get; }
/// <summary>
/// Gets the started timestamp.
/// </summary>
DateTime StartedTime { get; }
/// <summary>
/// Gets the stopped timestamp.
/// </summary>
DateTime StoppedTime { get; }
/// <summary>
/// Gets the logger.
/// </summary>
[NotNull]
ILogger Logger { get; }
/// <summary>
/// Gets the container id.
/// </summary>
/// <exception cref="InvalidOperationException">Container has not been created.</exception>
[NotNull]
string Id { get; }
/// <summary>
/// Gets the container name.
/// </summary>
/// <exception cref="InvalidOperationException">Container has not been created.</exception>
[NotNull]
string Name { get; }
/// <summary>
/// Gets the container IP address.
/// </summary>
/// <exception cref="InvalidOperationException">Container has not been created.</exception>
[NotNull]
string IpAddress { get; }
/// <summary>
/// Gets the container MAC address.
/// </summary>
/// <exception cref="InvalidOperationException">Container has not been created.</exception>
[NotNull]
string MacAddress { get; }
/// <summary>
/// Gets the container hostname.
/// </summary>
/// <exception cref="InvalidOperationException">Container has not been created.</exception>
[NotNull]
string Hostname { get; }
/// <summary>
/// Gets the container image.
/// </summary>
[NotNull]
IImage Image { get; }
/// <summary>
/// Gets the container state.
/// </summary>
TestcontainersStates State { get; }
/// <summary>
/// Gets the container health status.
/// </summary>
TestcontainersHealthStatus Health { get; }
/// <summary>
/// Gets the container health check failing streak.
/// </summary>
long HealthCheckFailingStreak { get; }
/// <summary>
/// Resolves the public assigned host port.
/// </summary>
/// <param name="containerPort">The container port.</param>
/// <returns>Returns the public assigned host port.</returns>
/// <exception cref="InvalidOperationException">Container has not been created.</exception>
ushort GetMappedPublicPort(int containerPort);
/// <summary>
/// Resolves the public assigned host port.
/// </summary>
/// <param name="containerPort">The container port.</param>
/// <returns>Returns the public assigned host port.</returns>
/// <exception cref="InvalidOperationException">Container has not been created.</exception>
ushort GetMappedPublicPort(string containerPort);
/// <summary>
/// Gets the container exit code.
/// </summary>
/// <param name="ct">Cancellation token.</param>
/// <returns>Returns the container exit code.</returns>
Task<long> GetExitCodeAsync(CancellationToken ct = default);
/// <summary>
/// Gets the container logs.
/// </summary>
/// <param name="since">Only logs since this time.</param>
/// <param name="until">Only logs until this time.</param>
/// <param name="timestampsEnabled">Determines whether every log line contains a timestamp or not.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>Returns the container logs.</returns>
Task<(string Stdout, string Stderr)> GetLogsAsync(DateTime since = default, DateTime until = default, bool timestampsEnabled = true, CancellationToken ct = default);
/// <summary>
/// Starts the container.
/// </summary>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the container has been started.</returns>
/// <exception cref="OperationCanceledException">Thrown when a Docker API call gets canceled.</exception>
/// <exception cref="TaskCanceledException">Thrown when a Testcontainers task gets canceled.</exception>
/// <exception cref="TimeoutException">Thrown when the wait strategy task gets canceled or the timeout expires.</exception>
Task StartAsync(CancellationToken ct = default);
/// <summary>
/// Stops the container.
/// </summary>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the container has been stopped.</returns>
/// <exception cref="OperationCanceledException">Thrown when a Docker API call gets canceled.</exception>
/// <exception cref="TaskCanceledException">Thrown when a Testcontainers task gets canceled.</exception>
Task StopAsync(CancellationToken ct = default);
/// <summary>
/// Copies a test host file to the container.
/// </summary>
/// <param name="fileContent">The byte array content of the file.</param>
/// <param name="filePath">The target file path to copy the file to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns></returns>
Task CopyAsync(byte[] fileContent, string filePath, UnixFileModes fileMode = Unix.FileMode644, CancellationToken ct = default);
/// <summary>
/// Copies a test host directory or file to the container.
/// </summary>
/// <param name="source">The source directory or file to be copied.</param>
/// <param name="target">The target directory path to copy the files to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>A task that completes when the directory or file has been copied.</returns>
Task CopyAsync(string source, string target, UnixFileModes fileMode = Unix.FileMode644, CancellationToken ct = default);
/// <summary>
/// Copies a test host directory to the container.
/// </summary>
/// <param name="source">The source directory to be copied.</param>
/// <param name="target">The target directory path to copy the files to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>A task that completes when the directory has been copied.</returns>
Task CopyAsync(DirectoryInfo source, string target, UnixFileModes fileMode = Unix.FileMode644, CancellationToken ct = default);
/// <summary>
/// Copies a test host file to the container.
/// </summary>
/// <param name="source">The source file to be copied.</param>
/// <param name="target">The target directory path to copy the file to.</param>
/// <param name="fileMode">The POSIX file mode permission.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>A task that completes when the file has been copied.</returns>
Task CopyAsync(FileInfo source, string target, UnixFileModes fileMode = Unix.FileMode644, CancellationToken ct = default);
/// <summary>
/// Reads a file from the container.
/// </summary>
/// <param name="filePath">An absolute path or a name value within the container.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the file has been read.</returns>
Task<byte[]> ReadFileAsync(string filePath, CancellationToken ct = default);
/// <summary>
/// Executes a command in the container.
/// </summary>
/// <param name="command">Shell command.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the shell command has been executed.</returns>
Task<ExecResult> ExecAsync(IList<string> command, CancellationToken ct = default);
}
}