Skip to content

Commit

Permalink
chore!: Remove legacy TestcontainersNetworkBuilder, IDockerNetwork (#804
Browse files Browse the repository at this point in the history
)
  • Loading branch information
HofmeisterAn committed Feb 27, 2023
1 parent 69453ec commit 1fe8d56
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 67 deletions.
32 changes: 0 additions & 32 deletions src/Testcontainers/BackwardCompatibility/BackwardsCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,6 @@ public DockerImage(IDockerImage image)
}
}

namespace Networks
{
[PublicAPI]
[Obsolete("Use the INetwork interface instead.")]
public interface IDockerNetwork
{
[NotNull]
string Name { get; }

Task CreateAsync(CancellationToken ct = default);

Task DeleteAsync(CancellationToken ct = default);
}

/// <summary>
/// Maps the old to the new interface to provide backwards compatibility.
/// </summary>
internal sealed partial class DockerNetwork
{
public DockerNetwork(IDockerNetwork network)
{
this.network.Name = network.Name;
}
}
}

namespace Volumes
{
[PublicAPI]
Expand Down Expand Up @@ -182,12 +156,6 @@ public sealed class TestcontainersBuilder<TContainerEntity> : ContainerBuilder<T
{
}

[PublicAPI]
[Obsolete("Use the NetworkBuilder class instead.")]
public sealed class TestcontainersNetworkBuilder : NetworkBuilder
{
}

[PublicAPI]
[Obsolete("Use the VolumeBuilder class instead.")]
public sealed class TestcontainersVolumeBuilder : VolumeBuilder
Expand Down
5 changes: 0 additions & 5 deletions src/Testcontainers/Builders/ContainerBuilder`3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,6 @@ public TBuilderEntity WithImage(IDockerImage image)
return this.WithImage(new DockerImage(image));
}

public TBuilderEntity WithNetwork(IDockerNetwork network)
{
return this.WithNetwork(new DockerNetwork(network));
}

public TBuilderEntity WithVolumeMount(IDockerVolume volume, string destination)
{
return this.WithVolumeMount(new DockerVolume(volume), destination);
Expand Down
3 changes: 0 additions & 3 deletions src/Testcontainers/Builders/IContainerBuilder`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@ public interface IContainerBuilder<out TBuilderEntity, out TContainerEntity> : I
[Obsolete("Use WithImage(IImage) instead.")]
TBuilderEntity WithImage(IDockerImage image);

[Obsolete("Use WithNetwork(INetwork) instead.")]
TBuilderEntity WithNetwork(IDockerNetwork network);

[Obsolete("Use WithVolumeMount(IVolume, string) instead.")]
TBuilderEntity WithVolumeMount(IDockerVolume volume, string destination);

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers/Networks/DockerNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DotNet.Testcontainers.Networks

/// <inheritdoc cref="INetwork" />
[PublicAPI]
internal sealed partial class DockerNetwork : Resource, INetwork
internal sealed class DockerNetwork : Resource, INetwork
{
private readonly IDockerNetworkOperations dockerNetworkOperations;

Expand Down
20 changes: 2 additions & 18 deletions src/Testcontainers/Networks/INetwork.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
namespace DotNet.Testcontainers.Networks
{
using System;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;

/// <summary>
/// A network instance.
/// </summary>
[PublicAPI]
public interface INetwork : IDockerNetwork, IFutureResource
public interface INetwork : IFutureResource
{
/// <summary>
/// Gets the name.
/// </summary>
/// <exception cref="InvalidOperationException">Network has not been created.</exception>
[NotNull]
new string Name { get; }

/// <summary>
/// Creates the network.
/// </summary>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the network has been created.</returns>
new Task CreateAsync(CancellationToken ct = default);

/// <summary>
/// Deletes the network.
/// </summary>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the network has been deleted.</returns>
new Task DeleteAsync(CancellationToken ct = default);
string Name { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1"/>
<PackageReference Include="coverlet.msbuild" Version="3.2.0"/>
<PackageReference Include="coverlet.collector" Version="3.2.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="Confluent.Kafka" Version="2.0.2"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
[UsedImplicitly]
public sealed class NetworkFixture : IAsyncLifetime
{
public IDockerNetwork Network { get; }
= new TestcontainersNetworkBuilder()
public INetwork Network { get; }
= new NetworkBuilder()
.WithDriver(NetworkDriver.Bridge)
.WithName(Guid.NewGuid().ToString("D"))
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void QueryImageInformationOfNotCreatedImage()
public void QueryNetworkInformationOfNotCreatedNetwork()
{
// Given
var networkBuilder = new TestcontainersNetworkBuilder()
var networkBuilder = new NetworkBuilder()
.WithName(Guid.NewGuid().ToString("D"));

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class TestcontainerNetworkBuilderTest : IClassFixture<Testcontaine

private static readonly KeyValuePair<string, string> ParameterModifier = new KeyValuePair<string, string>(TestcontainersClient.TestcontainersLabel + ".parameter.modifier", Guid.NewGuid().ToString("D"));

private readonly IDockerNetwork network;
private readonly INetwork network;

public TestcontainerNetworkBuilderTest(DockerNetwork network)
{
Expand All @@ -33,7 +33,7 @@ public TestcontainerNetworkBuilderTest(DockerNetwork network)
[Fact]
public void GetNameThrowsInvalidOperationException()
{
_ = Assert.Throws<InvalidOperationException>(() => new TestcontainersNetworkBuilder()
_ = Assert.Throws<InvalidOperationException>(() => new NetworkBuilder()
.WithName(NetworkName)
.Build()
.Name);
Expand Down Expand Up @@ -74,9 +74,9 @@ public async Task CreateNetworkAssignsLabels()
}

[UsedImplicitly]
public sealed class DockerNetwork : IDockerNetwork, IAsyncLifetime
public sealed class DockerNetwork : INetwork, IAsyncLifetime
{
private readonly IDockerNetwork network = new TestcontainersNetworkBuilder()
private readonly INetwork network = new NetworkBuilder()
.WithName(NetworkName)
.WithOption(Option.Key, Option.Value)
.WithLabel(Label.Key, Label.Value)
Expand Down

0 comments on commit 1fe8d56

Please sign in to comment.