From b0b0acbf57ac152cf8a10d93a83ea6480b0a11f8 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Tue, 10 Oct 2023 19:34:29 +0200 Subject: [PATCH] chore: Do not return default resource type --- src/Testcontainers/Clients/DockerContainerOperations.cs | 8 +++----- src/Testcontainers/Clients/DockerImageOperations.cs | 8 +++----- src/Testcontainers/Clients/DockerNetworkOperations.cs | 8 +++----- src/Testcontainers/Clients/DockerVolumeOperations.cs | 8 +++----- src/Testcontainers/Images/PullPolicy.cs | 3 +-- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/Testcontainers/Clients/DockerContainerOperations.cs b/src/Testcontainers/Clients/DockerContainerOperations.cs index b4d4f0165..de7526acc 100644 --- a/src/Testcontainers/Clients/DockerContainerOperations.cs +++ b/src/Testcontainers/Clients/DockerContainerOperations.cs @@ -14,8 +14,6 @@ namespace DotNet.Testcontainers.Clients internal sealed class DockerContainerOperations : DockerApiClient, IDockerContainerOperations { - private static readonly ContainerInspectResponse NoSuchContainer = new ContainerInspectResponse(); - private readonly ILogger _logger; public DockerContainerOperations(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, ILogger logger) @@ -55,7 +53,7 @@ public async Task ByPropertyAsync(string property, str } catch (DockerApiException) { - return NoSuchContainer; + return null; } } @@ -64,7 +62,7 @@ public async Task ExistsWithIdAsync(string id, CancellationToken ct = defa var response = await ByIdAsync(id, ct) .ConfigureAwait(false); - return !NoSuchContainer.Equals(response); + return response != null; } public async Task ExistsWithNameAsync(string name, CancellationToken ct = default) @@ -72,7 +70,7 @@ public async Task ExistsWithNameAsync(string name, CancellationToken ct = var response = await ByNameAsync(name, ct) .ConfigureAwait(false); - return !NoSuchContainer.Equals(response); + return response != null; } public async Task GetExitCodeAsync(string id, CancellationToken ct = default) diff --git a/src/Testcontainers/Clients/DockerImageOperations.cs b/src/Testcontainers/Clients/DockerImageOperations.cs index d23e47f23..f469bd569 100644 --- a/src/Testcontainers/Clients/DockerImageOperations.cs +++ b/src/Testcontainers/Clients/DockerImageOperations.cs @@ -18,8 +18,6 @@ internal sealed class DockerImageOperations : DockerApiClient, IDockerImageOpera private readonly TraceProgress _traceProgress; - public static readonly ImageInspectResponse NoSuchImage = new ImageInspectResponse(); - public DockerImageOperations(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, ILogger logger) : base(sessionId, dockerEndpointAuthConfig) { @@ -58,7 +56,7 @@ public async Task ByPropertyAsync(string property, string } catch (DockerApiException) { - return NoSuchImage; + return null; } } @@ -67,7 +65,7 @@ public async Task ExistsWithIdAsync(string id, CancellationToken ct = defa var response = await ByIdAsync(id, ct) .ConfigureAwait(false); - return !NoSuchImage.Equals(response); + return response != null; } public async Task ExistsWithNameAsync(string name, CancellationToken ct = default) @@ -75,7 +73,7 @@ public async Task ExistsWithNameAsync(string name, CancellationToken ct = var response = await ByNameAsync(name, ct) .ConfigureAwait(false); - return !NoSuchImage.Equals(response); + return response != null; } public async Task CreateAsync(IImage image, IDockerRegistryAuthenticationConfiguration dockerRegistryAuthConfig, CancellationToken ct = default) diff --git a/src/Testcontainers/Clients/DockerNetworkOperations.cs b/src/Testcontainers/Clients/DockerNetworkOperations.cs index 2b5f8f0b1..503db9c0e 100644 --- a/src/Testcontainers/Clients/DockerNetworkOperations.cs +++ b/src/Testcontainers/Clients/DockerNetworkOperations.cs @@ -12,8 +12,6 @@ namespace DotNet.Testcontainers.Clients internal sealed class DockerNetworkOperations : DockerApiClient, IDockerNetworkOperations { - private static readonly NetworkResponse NoSuchNetwork = new NetworkResponse(); - private readonly ILogger _logger; public DockerNetworkOperations(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, ILogger logger) @@ -53,7 +51,7 @@ public async Task ByPropertyAsync(string property, string value } catch (DockerApiException) { - return NoSuchNetwork; + return null; } } @@ -62,7 +60,7 @@ public async Task ExistsWithIdAsync(string id, CancellationToken ct = defa var response = await ByIdAsync(id, ct) .ConfigureAwait(false); - return !NoSuchNetwork.Equals(response); + return response != null; } public async Task ExistsWithNameAsync(string name, CancellationToken ct = default) @@ -70,7 +68,7 @@ public async Task ExistsWithNameAsync(string name, CancellationToken ct = var response = await ByNameAsync(name, ct) .ConfigureAwait(false); - return !NoSuchNetwork.Equals(response); + return response != null; } public async Task CreateAsync(INetworkConfiguration configuration, CancellationToken ct = default) diff --git a/src/Testcontainers/Clients/DockerVolumeOperations.cs b/src/Testcontainers/Clients/DockerVolumeOperations.cs index 350b6c4cc..4224bd92b 100644 --- a/src/Testcontainers/Clients/DockerVolumeOperations.cs +++ b/src/Testcontainers/Clients/DockerVolumeOperations.cs @@ -12,8 +12,6 @@ namespace DotNet.Testcontainers.Clients internal sealed class DockerVolumeOperations : DockerApiClient, IDockerVolumeOperations { - private static readonly VolumeResponse NoSuchVolume = new VolumeResponse(); - private readonly ILogger _logger; public DockerVolumeOperations(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, ILogger logger) @@ -57,7 +55,7 @@ public async Task ByPropertyAsync(string property, string value, } catch (DockerApiException) { - return NoSuchVolume; + return null; } } @@ -66,7 +64,7 @@ public async Task ExistsWithIdAsync(string id, CancellationToken ct = defa var response = await ByIdAsync(id, ct) .ConfigureAwait(false); - return !NoSuchVolume.Equals(response); + return response != null; } public async Task ExistsWithNameAsync(string name, CancellationToken ct = default) @@ -74,7 +72,7 @@ public async Task ExistsWithNameAsync(string name, CancellationToken ct = var response = await ByNameAsync(name, ct) .ConfigureAwait(false); - return !NoSuchVolume.Equals(response); + return response != null; } public async Task CreateAsync(IVolumeConfiguration configuration, CancellationToken ct = default) diff --git a/src/Testcontainers/Images/PullPolicy.cs b/src/Testcontainers/Images/PullPolicy.cs index 73a3dfb44..b5a852d2c 100644 --- a/src/Testcontainers/Images/PullPolicy.cs +++ b/src/Testcontainers/Images/PullPolicy.cs @@ -2,7 +2,6 @@ namespace DotNet.Testcontainers.Images { using System; using Docker.DotNet.Models; - using DotNet.Testcontainers.Clients; using JetBrains.Annotations; /// @@ -29,7 +28,7 @@ public static Func Missing { get { - return cachedImage => DockerImageOperations.NoSuchImage.Equals(cachedImage); + return cachedImage => cachedImage == null; } }