feat: create networks with random names#1993
Merged
mdelapenya merged 12 commits intotestcontainers:mainfrom Dec 18, 2023
Merged
feat: create networks with random names#1993mdelapenya merged 12 commits intotestcontainers:mainfrom
mdelapenya merged 12 commits intotestcontainers:mainfrom
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Because it was introduced in the current release, it's fine to change the signature
It relates to Docker Swarm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR creates a new
networkpackage that will allow Go users to use thepackage.Newidiom when creating a Docker network with Testcontainers for Go.This new package exposes functional options representing the former
NetworkRequeststruct, 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:
Newfunction, and read the name from there.Finally, the new
networkpackage will have this:Newfunction will return a struct, not an interface as in the previousGenericNetwork: 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.NetworkCustomizerinterface in the case consumers want to define their own options to create the network customising more Docker types. Implementing theCustomizefunction will be enough.WithNetworkfunctional 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.WithNewNetworkfunctional option to be used in modules has been added. It will create a new network using the functions and options in thenetworkpackage.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: