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

feat: create networks with random names #1993

Merged

Conversation

mdelapenya
Copy link
Collaborator

@mdelapenya mdelapenya commented Dec 14, 2023

  • chore: handle error in test
  • feat: add a first-order package for creating networks

What does this PR do?

This PR creates a new network package that will allow Go users to use the package.New idiom when creating a Docker network with Testcontainers for Go.

This new package exposes functional options representing the former NetworkRequest struct, so that users of the old struct are still able to convert their code to the new format using this deprecation path: instead of creating a Network request, please pass functional options with the needed settings.

As a consequence, the old code to create a network has been deprecated, and will eventually removed in the next major version (v1).

To continue, it's important to mention that the new network will be created with a random name: instead of passing the name as before, we want names to be non-deterministic. And this comes with two benefits:

  1. alignment with other Testcontainers libraries
  2. users' code won't need to "remember" the network name, simply get the struct returned by the New function, and read the name from there.

Finally, the new network package will have this:

  • the New function will return a struct, not an interface as in the previous GenericNetwork: we want to adhere to the Go idiom of "accept interface, return struct" so the consumer of the method can work with the expected, concrete, returned type, not dealing with an abstraction. In other words: producers should produce concrete types to consumers.
  • it defines some functional options to configure the creation of the network, also exposing the NetworkCustomizer interface in the case consumers want to define their own options to create the network customising more Docker types. Implementing the Customize function will be enough.
  • The WithNetwork functional option used in modules, not released yet, has been moved here and refactored a bit to allow receiving an already created Network struct, and use it in downstream containers.
  • A WithNewNetwork functional option to be used in modules has been added. It will create a new network using the functions and options in the network package.

Why is it important?

We want users to create networks with random names. We have stepped-up here to create a new package, which will be a PoC for an eventual v1 release, in which we could have first-order packages for the different entities we manage: networks, images, volumes and containers.

Related issues

How to test this PR

Please read the docs: https://deploy-preview-1993--testcontainers-go.netlify.app/features/creating_networks/ there we explain how the new APIs are used.

All the modules will receive two new options:

@mdelapenya mdelapenya requested a review from a team as a code owner December 14, 2023 16:58
@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label Dec 14, 2023
@mdelapenya mdelapenya self-assigned this Dec 14, 2023
Copy link

netlify bot commented Dec 14, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit b02232c
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/65808045e801a300084a4a5b
😎 Deploy Preview https://deploy-preview-1993--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

network/network.go Outdated Show resolved Hide resolved
network/network.go Outdated Show resolved Hide resolved
network/network.go Show resolved Hide resolved
@mdelapenya mdelapenya merged commit 2120c33 into testcontainers:main Dec 18, 2023
116 checks passed
@mdelapenya mdelapenya deleted the network-name-non-deterministic branch December 18, 2023 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: create networks using random names
2 participants