Skip to content

Commit

Permalink
chore: Do not return default resource type
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Oct 10, 2023
1 parent 0da59d7 commit b0b0acb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
8 changes: 3 additions & 5 deletions src/Testcontainers/Clients/DockerContainerOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -55,7 +53,7 @@ public async Task<ContainerInspectResponse> ByPropertyAsync(string property, str
}
catch (DockerApiException)
{
return NoSuchContainer;
return null;
}
}

Expand All @@ -64,15 +62,15 @@ public async Task<bool> ExistsWithIdAsync(string id, CancellationToken ct = defa
var response = await ByIdAsync(id, ct)
.ConfigureAwait(false);

return !NoSuchContainer.Equals(response);
return response != null;
}

public async Task<bool> ExistsWithNameAsync(string name, CancellationToken ct = default)
{
var response = await ByNameAsync(name, ct)
.ConfigureAwait(false);

return !NoSuchContainer.Equals(response);
return response != null;
}

public async Task<long> GetExitCodeAsync(string id, CancellationToken ct = default)
Expand Down
8 changes: 3 additions & 5 deletions src/Testcontainers/Clients/DockerImageOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -58,7 +56,7 @@ public async Task<ImageInspectResponse> ByPropertyAsync(string property, string
}
catch (DockerApiException)
{
return NoSuchImage;
return null;
}
}

Expand All @@ -67,15 +65,15 @@ public async Task<bool> ExistsWithIdAsync(string id, CancellationToken ct = defa
var response = await ByIdAsync(id, ct)
.ConfigureAwait(false);

return !NoSuchImage.Equals(response);
return response != null;
}

public async Task<bool> ExistsWithNameAsync(string name, CancellationToken ct = default)
{
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)
Expand Down
8 changes: 3 additions & 5 deletions src/Testcontainers/Clients/DockerNetworkOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -53,7 +51,7 @@ public async Task<NetworkResponse> ByPropertyAsync(string property, string value
}
catch (DockerApiException)
{
return NoSuchNetwork;
return null;
}
}

Expand All @@ -62,15 +60,15 @@ public async Task<bool> ExistsWithIdAsync(string id, CancellationToken ct = defa
var response = await ByIdAsync(id, ct)
.ConfigureAwait(false);

return !NoSuchNetwork.Equals(response);
return response != null;
}

public async Task<bool> ExistsWithNameAsync(string name, CancellationToken ct = default)
{
var response = await ByNameAsync(name, ct)
.ConfigureAwait(false);

return !NoSuchNetwork.Equals(response);
return response != null;
}

public async Task<string> CreateAsync(INetworkConfiguration configuration, CancellationToken ct = default)
Expand Down
8 changes: 3 additions & 5 deletions src/Testcontainers/Clients/DockerVolumeOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -57,7 +55,7 @@ public async Task<VolumeResponse> ByPropertyAsync(string property, string value,
}
catch (DockerApiException)
{
return NoSuchVolume;
return null;
}
}

Expand All @@ -66,15 +64,15 @@ public async Task<bool> ExistsWithIdAsync(string id, CancellationToken ct = defa
var response = await ByIdAsync(id, ct)
.ConfigureAwait(false);

return !NoSuchVolume.Equals(response);
return response != null;
}

public async Task<bool> ExistsWithNameAsync(string name, CancellationToken ct = default)
{
var response = await ByNameAsync(name, ct)
.ConfigureAwait(false);

return !NoSuchVolume.Equals(response);
return response != null;
}

public async Task<string> CreateAsync(IVolumeConfiguration configuration, CancellationToken ct = default)
Expand Down
3 changes: 1 addition & 2 deletions src/Testcontainers/Images/PullPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace DotNet.Testcontainers.Images
{
using System;
using Docker.DotNet.Models;
using DotNet.Testcontainers.Clients;
using JetBrains.Annotations;

/// <summary>
Expand All @@ -29,7 +28,7 @@ public static Func<ImageInspectResponse, bool> Missing
{
get
{
return cachedImage => DockerImageOperations.NoSuchImage.Equals(cachedImage);
return cachedImage => cachedImage == null;
}
}

Expand Down

0 comments on commit b0b0acb

Please sign in to comment.