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

Feature/455 Added WithNetworkAliases functionality #480

Merged

Conversation

vlaskal
Copy link
Contributor

@vlaskal vlaskal commented Jun 16, 2022

This PR should bring new functionality WithNetworkAliases to ITestcontainersBuilder<>

    /// <summary>
    /// Assign specified network aliases to container.
    /// </summary>
    /// <param name="networkAliases">Set of network aliases.</param>
    /// <returns>A configured instance of <see cref="ITestcontainersBuilder{TDockerContainer}" />.</returns>
    [PublicAPI]
    ITestcontainersBuilder<TDockerContainer> WithNetworkAliases(params string[] networkAliases);

    /// <summary>
    /// Assign specified network aliases to container.
    /// </summary>
    /// <param name="networkAliases">Set of network aliases.</param>
    /// <returns>A configured instance of <see cref="ITestcontainersBuilder{TDockerContainer}" />.</returns>
    [PublicAPI]
    ITestcontainersBuilder<TDockerContainer> WithNetworkAliases(IEnumerable<string> networkAliases);

@vlaskal vlaskal marked this pull request as ready for review June 16, 2022 21:17
Copy link
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. I can do the review in the next days. Today I’m busy.

@HofmeisterAn HofmeisterAn force-pushed the feature/455-WithNetworkAliases branch from 1592305 to 3831a37 Compare June 18, 2022 21:22
Copy link
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I expressed myself unclear. What I meant is, that you can use a similar or the same approach to test your changes, like TestcontainersNetworkTest and NetworkFixture does.

You can revert the changes in TestcontainersNetworkTest and NetworkFixture and replace it with something like:

diff --git a/tests/Testcontainers.Tests/Unit/Networks/TestcontainersNetworkTest.cs b/tests/Testcontainers.Tests/Unit/Networks/TestcontainersNetworkTest.cs
index 01a0e26..b5cb7aa 100644
--- a/tests/Testcontainers.Tests/Unit/Networks/TestcontainersNetworkTest.cs
+++ b/tests/Testcontainers.Tests/Unit/Networks/TestcontainersNetworkTest.cs
@@ -9,6 +9,8 @@ namespace DotNet.Testcontainers.Tests.Unit
   [Collection(nameof(Testcontainers))]
   public sealed class TestcontainersNetworkTest : IClassFixture<NetworkFixture>, IAsyncLifetime
   {
+    private const string Alias = "-alias";
+
     private readonly ITestcontainersContainer testcontainer1;
 
     private readonly ITestcontainersContainer testcontainer2;
@@ -22,10 +24,12 @@ namespace DotNet.Testcontainers.Tests.Unit
 
       this.testcontainer1 = testcontainersBuilder
         .WithHostname(nameof(this.testcontainer1))
+        .WithNetworkAliases(nameof(this.testcontainer1) + Alias)
         .Build();
 
       this.testcontainer2 = testcontainersBuilder
         .WithHostname(nameof(this.testcontainer2))
+        .WithNetworkAliases(nameof(this.testcontainer2) + Alias)
         .Build();
     }
 
@@ -39,10 +43,14 @@ namespace DotNet.Testcontainers.Tests.Unit
       return Task.WhenAll(this.testcontainer1.DisposeAsync().AsTask(), this.testcontainer2.DisposeAsync().AsTask());
     }
 
-    [Fact]
-    public async Task PingContainer()
+    [Theory]
+    [InlineData(nameof(testcontainer2))]
+    [InlineData(nameof(testcontainer2) + Alias)]
+    public async Task Ping(string destination)
     {
-      Assert.Equal(0, (await this.testcontainer1.ExecAsync(new[] { "ping", "-c", "4", nameof(this.testcontainer2) })).ExitCode);
+      var execResult = await this.testcontainer1.ExecAsync(new[] { "ping", "-c", "4", destination })
+        .ConfigureAwait(false);
+      Assert.Equal(0, execResult.ExitCode);
     }
   }
 }

If you know how it works, it would be nice if you squash your commits to a single commit.

@vlaskal vlaskal force-pushed the feature/455-WithNetworkAliases branch from 0a4072c to 80637b9 Compare June 20, 2022 20:51
@vlaskal
Copy link
Contributor Author

vlaskal commented Jun 20, 2022

You can revert the changes in TestcontainersNetworkTest and NetworkFixture and replace it with something like:

Updated - nice design

@vlaskal
Copy link
Contributor Author

vlaskal commented Jun 20, 2022

If you know how it works, it would be nice if you squash your commits to a single commit.

Squashed as you wanted

@vlaskal vlaskal force-pushed the feature/455-WithNetworkAliases branch from 80637b9 to ccb3976 Compare June 20, 2022 21:04
@HofmeisterAn HofmeisterAn merged commit ccb3976 into testcontainers:develop Jun 21, 2022
@HofmeisterAn
Copy link
Collaborator

Published in 2.0.0, closes #455.

@vlaskal vlaskal deleted the feature/455-WithNetworkAliases branch June 26, 2022 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants