Open johnnyggalt opened 1 month ago
Hi, at this point, this is intentional. Modules are pre-configured, opinionated, and follow best practices (configurations) driven by the community. The builder API is "immutable" to support A/B testing, it is currently not possible to override (remove) configurations for most elements that rely on lists or dictionaries (due to the way the BuildConfiguration
works).
Supporting a feature that allows developers to entirely override the configuration would likely be a good enhancement, but it should be implemented explicitly. There are many variations that could potentially break the pre-configured module configuration, and developers should be aware that this could easily cause issues.
However, if a module's configuration does not suit your use case, you can always fall back to the generic builder and configure it yourself.
Thanks @HofmeisterAn ...
you can always fall back to the generic builder and configure it yourself
Can you please clarify this? Do you mean to extend ContainerBuilder<TBuilderEntity, TContainerEntity, TConfigurationEntity>
myself? If so, that's what I've done as a workaround, but it turned into quite a thing as compared to simply overriding a deafult value or, absent that ability, inheriting from KeycloakBuilder
and overriding its behavior.
Can you please clarify this? Do you mean to extend
ContainerBuilder<TBuilderEntity, TContainerEntity, TConfigurationEntity>
myself?
Yes, this is what I meant.
I've done as a workaround, but it turned into quite a thing as compared to simply overriding a deafult value or, absent that ability, inheriting from
KeycloakBuilder
and overriding its behavior.
I understand, but it is difficult to provide the desired flexibility, supporting all kinds of configurations and maintaining reliability at the same time.
Got it. Just for the record, I decided to use reflection to reduce the amount of code. It's in my test fixture anyway, so not a huge deal.
type KeycloakBuilder with
member this.WithOptimizedStartup() =
let keycloakConfiguration =
this
.GetType()
.GetProperty("DockerResourceConfiguration", BindingFlags.Instance ||| BindingFlags.NonPublic ||| BindingFlags.DeclaredOnly)
.GetValue(this)
:?> KeycloakConfiguration
if keycloakConfiguration = null then
failwith "Failed to resolve DockerResourceConfiguration property on KeycloakConfiguration"
let commandField =
keycloakConfiguration
.GetType()
.BaseType
.GetFields(BindingFlags.Instance ||| BindingFlags.NonPublic)
|> Array.tryFind _.Name.StartsWith("<Command>")
|> Option.toObj
if commandField = null then
failwith "Failed to resolve backing field for ContainerConfiguration.Command property"
commandField.SetValue(keycloakConfiguration, [ "start"; "--optimized" ] |> box)
this
If you like, we can keep the issue open. IMO, it is a valid feature request to be able to override module configurations. With the current design, overriding some parts is very tricky, especially when trying to prevent developers from making misconfigurations. However, we might find a better design that allows developers to properly override module configurations while also creating awareness that with the overridden values, wait strategies, connection strings, etc., may not work as expected anymore.
Sure thing, thanks
Testcontainers version
3.9.0
Using the latest Testcontainers version?
Yes
Host OS
Windows
Host arch
x86
.NET version
8.0.303
Docker version
Docker info
What happened?
When building a container - any container, but in my case Keycloak - specifying a different command results in merging. If the
ContainerBuilder
already defines a "default" command, there's seemingly no way to replace that command completely. For example:This will result in an attempt to run the command
start-dev start
rather than the desiredstart
becauseKeycloakBuilder.Init
already invokes.WithCommand("start-dev")
. Moreover, I cannot find a way to supplant the default like you can with non-enumerable values. The easiest thing to do for a quick workaround would be to inheritKeycloakBuilder
and overrideInit
so that it doesn't invokeWithCommand
, butKeycloakBuilder
issealed
.Relevant log output
No response
Additional information
No response