Creating container requests: separation of concerns #628
Replies: 3 comments 17 replies
-
It looks like we are using a list of callbacks in Java and .NET. TBH, I do not see any advantages of a list, @eddumelendez @kiview do you know any? To keep the languages consistent, I suggest nonetheless a list of callbacks. |
Beta Was this translation helpful? Give feedback.
-
Adding here a Slack thread: @hhsnopek |
Beta Was this translation helpful? Give feedback.
-
I think we can close this discussion, as it has already been implemented |
Beta Was this translation helpful? Give feedback.
-
Hi Testcontainers Gophers! We'd like to share in this discussion that, in the light of #590 (reply in thread), we are going to start changing how the
ContainerRequest
is created regarding basic and more advanced settings.At this moment, the
ContainerRequest
struct establishes an almost 1-1 relationship with the Docker types, so that it's very straightforward to set up anything in the container directly from a field in theContainerRequest
. We think this is fine. At the same time, we see that exposing certain configurations in theContainerRequest
, such as advanced networking or advanced host-config settings, could lead to unexpected behaviors or potentials setup errors if those advanced fields are not properly used by the consumers of the library.Another side effect of this 1-1 mapping with the Docker types is that, at some point, the public API of Testcontainers for Go could reach to a state that it's almost undistinguishable from the Docker client: all the Docker types could be eventually exposed in the
ContainerRequest
, creating a Frankenstein struct with multiple fields and types that would make its usage more difficult and less maintenable.For those reasons, we are starting this discussion and offer a proposal that is working very well in other Testcontainers implementations, such as Java and .NET, which is creating a separation of concerns: basic fields and advanced fields:
container.Config
(portable information of the container) will live in this basic layer.We think that this change will keep the public API simple and usable, but still powerful to provide advanced setups to experts users (see the advanced use case shared by @oktalz here: #590 (reply in thread)). Simple because the >80% of the regular use cases will be still and directly available in the
ContainerRequest
, and powerful because theContainerRequest
will expose a mechanism to setup those advance settings.At the same time, the maintenance work on the library will be significatively reduced, as contributors won't need to send PRs to add/expose fields in the
ContainerRequest
, but just pre-configure the request with their own settings using a callback mechanism.Something like this is what we have in mind:
which will be internally used like this:
At the moment the callback appears in the public API, we'd like to start deprecating "advanced" settings from the container request, as it'd be possible to set them up using the pre-creation callback.
As always, we'd love to hear your feedback.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions