Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Invert #if NETSTANDARD* conditional compilation conditions #1079

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/Testcontainers/Clients/TestcontainersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public Task<long> GetContainerExitCodeAsync(string id, CancellationToken ct = de
/// <inheritdoc />
public Task<(string Stdout, string Stderr)> GetContainerLogsAsync(string id, DateTime since = default, DateTime until = default, bool timestampsEnabled = true, CancellationToken ct = default)
{
#if NETSTANDARD2_1_OR_GREATER
var unixEpoch = DateTime.UnixEpoch;
#else
#if NETSTANDARD2_0
var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
#else
var unixEpoch = DateTime.UnixEpoch;
#endif

if (default(DateTime).Equals(since))
Expand Down Expand Up @@ -269,13 +269,12 @@ public async Task<byte[]> ReadFileAsync(string id, string filePath, Cancellation

var readBytes = new byte[entry.Size];

#if NETSTANDARD2_1_OR_GREATER
_ = await tarInputStream.ReadAsync(new Memory<byte>(readBytes), ct)
.ConfigureAwait(false);
#else
#if NETSTANDARD2_0
_ = await tarInputStream.ReadAsync(readBytes, 0, readBytes.Length, ct)
.ConfigureAwait(false);
#else
_ = await tarInputStream.ReadAsync(readBytes, ct)
#endif
.ConfigureAwait(false);

return readBytes;
}
Expand Down
27 changes: 12 additions & 15 deletions src/Testcontainers/Containers/ResourceReaper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,12 @@ await tcpClient.ConnectAsync(host, port)
{
using (var messageBuffer = new MemoryStream())
{
#if NETSTANDARD2_1_OR_GREATER
await stream.WriteAsync(new ReadOnlyMemory<byte>(sendBytes), ct)
.ConfigureAwait(false);
#else
#if NETSTANDARD2_0
await stream.WriteAsync(sendBytes, 0, sendBytes.Length, ct)
.ConfigureAwait(false);
#else
await stream.WriteAsync(sendBytes, ct)
#endif
.ConfigureAwait(false);

await stream.FlushAsync(ct)
.ConfigureAwait(false);
Expand All @@ -321,13 +320,12 @@ await stream.FlushAsync(ct)

do
{
#if NETSTANDARD2_1_OR_GREATER
var numberOfBytes = await stream.ReadAsync(new Memory<byte>(readBytes), ct)
.ConfigureAwait(false);
#else
#if NETSTANDARD2_0
var numberOfBytes = await stream.ReadAsync(readBytes, 0, readBytes.Length, ct)
.ConfigureAwait(false);
#else
var numberOfBytes = await stream.ReadAsync(readBytes, ct)
#endif
.ConfigureAwait(false);

if (numberOfBytes == 0)
{
Expand Down Expand Up @@ -367,13 +365,12 @@ await Task.Delay(TimeSpan.FromSeconds(RetryTimeoutInSeconds), ct)
while (!_maintainConnectionCts.IsCancellationRequested)
{
// Keep the connection to Ryuk up.
#if NETSTANDARD2_1_OR_GREATER
_ = await stream.ReadAsync(new Memory<byte>(readBytes), _maintainConnectionCts.Token)
.ConfigureAwait(false);
#else
#if NETSTANDARD2_0
_ = await stream.ReadAsync(readBytes, 0, readBytes.Length, _maintainConnectionCts.Token)
.ConfigureAwait(false);
#else
_ = await stream.ReadAsync(readBytes, _maintainConnectionCts.Token)
#endif
.ConfigureAwait(false);
}
}
catch (OperationCanceledException)
Expand Down
9 changes: 4 additions & 5 deletions src/Testcontainers/Containers/TarOutputMemoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ public async Task AddAsync(IResourceMapping resourceMapping, CancellationToken c
await PutNextEntryAsync(tarEntry, ct)
.ConfigureAwait(false);

#if NETSTANDARD2_1_OR_GREATER
await WriteAsync(fileContent, ct)
.ConfigureAwait(false);
#else
#if NETSTANDARD2_0
await WriteAsync(fileContent, 0, fileContent.Length, ct)
.ConfigureAwait(false);
#else
await WriteAsync(fileContent, ct)
#endif
.ConfigureAwait(false);

await CloseEntryAsync(ct)
.ConfigureAwait(false);
Expand Down
6 changes: 3 additions & 3 deletions src/Testcontainers/Images/IgnoreFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ public string Replace(string input)
}

// Replace the last non recursive wildcard with a match-zero-or-one quantifier regular expression.
#if NETSTANDARD2_1_OR_GREATER
if (input.Contains('*') && index >= 0)
#else
#if NETSTANDARD2_0
if (input.Contains("*") && index >= 0)
#else
if (input.Contains('*') && index >= 0)
#endif
{
input = input.Remove(index, 1).Insert(index, $"{MatchAllExceptPathSeparator}?");
Expand Down