Skip to content

Commit ecc0cab

Browse files
committed
chore: Remove Sonar findings
1 parent 5746da2 commit ecc0cab

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

src/Testcontainers/Builders/RootlessUnixEndpointAuthenticationProvider.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace DotNet.Testcontainers.Builders
88

99
/// <inheritdoc cref="IDockerRegistryAuthenticationProvider" />
1010
[PublicAPI]
11-
internal class RootlessUnixEndpointAuthenticationProvider : DockerEndpointAuthenticationProvider
11+
internal partial class RootlessUnixEndpointAuthenticationProvider : DockerEndpointAuthenticationProvider
1212
{
1313
private const string DockerSocket = "docker.sock";
1414

@@ -104,10 +104,17 @@ private interface IUserIdentity
104104

105105
/// <inheritdoc cref="IUserIdentity" />
106106
[PublicAPI]
107-
private sealed class Darwin : IUserIdentity
107+
private sealed partial class Darwin : IUserIdentity
108108
{
109-
[DllImport("libSystem")]
109+
private const string LibraryName = "libSystem";
110+
111+
#if NET7_0_OR_GREATER
112+
[LibraryImport(LibraryName)]
113+
private static partial ushort getuid();
114+
#else
115+
[DllImport(LibraryName)]
110116
private static extern ushort getuid();
117+
#endif
111118

112119
/// <inheritdoc />
113120
public ushort GetUid()
@@ -118,10 +125,17 @@ public ushort GetUid()
118125

119126
/// <inheritdoc cref="IUserIdentity" />
120127
[PublicAPI]
121-
private sealed class Linux : IUserIdentity
128+
private sealed partial class Linux : IUserIdentity
122129
{
123-
[DllImport("libc")]
130+
private const string LibraryName = "libc";
131+
132+
#if NET7_0_OR_GREATER
133+
[LibraryImport(LibraryName)]
134+
private static partial ushort getuid();
135+
#else
136+
[DllImport(LibraryName)]
124137
private static extern ushort getuid();
138+
#endif
125139

126140
/// <inheritdoc />
127141
public ushort GetUid()

src/Testcontainers/Containers/DockerContainer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ public TestcontainersStates State
200200

201201
try
202202
{
203+
#if NETSTANDARD2_0
203204
return (TestcontainersStates)Enum.Parse(typeof(TestcontainersStates), _container.State.Status, true);
205+
#else
206+
return Enum.Parse<TestcontainersStates>(_container.State.Status, true);
207+
#endif
204208
}
205209
catch (Exception)
206210
{
@@ -226,7 +230,11 @@ public TestcontainersHealthStatus Health
226230

227231
try
228232
{
233+
#if NETSTANDARD2_0
229234
return (TestcontainersHealthStatus)Enum.Parse(typeof(TestcontainersHealthStatus), _container.State.Health.Status, true);
235+
#else
236+
return Enum.Parse<TestcontainersHealthStatus>(_container.State.Health.Status, true);
237+
#endif
230238
}
231239
catch (Exception)
232240
{

src/Testcontainers/Containers/ResourceReaper.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,25 @@ await Task.Delay(TimeSpan.FromSeconds(RetryTimeoutInSeconds), ct)
363363
if (indexOfNewLine == -1)
364364
{
365365
// We have not received the entire message yet. Read from stream again.
366+
#if NETSTANDARD2_0
366367
await messageBuffer.WriteAsync(readBytes, 0, numberOfBytes, ct)
367368
.ConfigureAwait(false);
369+
#else
370+
await messageBuffer.WriteAsync(readBytes.AsMemory(0, numberOfBytes), ct)
371+
.ConfigureAwait(false);
372+
#endif
368373

369374
hasAcknowledge = false;
370375
}
371376
else
372377
{
378+
#if NETSTANDARD2_0
373379
await messageBuffer.WriteAsync(readBytes, 0, indexOfNewLine, ct)
374380
.ConfigureAwait(false);
381+
#else
382+
await messageBuffer.WriteAsync(readBytes.AsMemory(0, indexOfNewLine), ct)
383+
.ConfigureAwait(false);
384+
#endif
375385

376386
hasAcknowledge = "ack".Equals(Encoding.ASCII.GetString(messageBuffer.ToArray()), StringComparison.OrdinalIgnoreCase);
377387
messageBuffer.SetLength(0);

src/Testcontainers/Testcontainers.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<Configurations>Debug;Release</Configurations>
66
<RootNamespace>DotNet.Testcontainers</RootNamespace>
77
</PropertyGroup>
8+
<PropertyGroup>
9+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
10+
</PropertyGroup>
811
<ItemGroup>
912
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/>
1013
<PackageReference Include="Docker.DotNet.Enhanced.X509"/>

0 commit comments

Comments
 (0)