You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another overloaded member of the container builder API allows you to copy the contents of a byte array to a specific file path within the container. This can be useful when you already have the file content stored in memory or when you need to dynamically generate the file content before copying it.
@@ -97,6 +100,37 @@ _ = new ContainerBuilder()
97
100
98
101
The static class `Consume` offers pre-configured implementations of the `IOutputConsumer` interface for common use cases. If you need additional functionalities beyond those provided by the default implementations, you can create your own implementations of `IOutputConsumer`.
99
102
103
+
## Composing command arguments
104
+
105
+
Testcontainers for .NET provides the `WithCommand(ComposableEnumerable<string>)` API to give you flexible control over container command arguments. While currently used for container commands, the `ComposableEnumerable<T>` abstraction is designed to support other builder APIs in the future, allowing similar composition and override functionality.
106
+
107
+
Because our builders are immutable, this feature allows you to extend or override pre-configured configurations, such as those in Testcontainers [modules](../modules/index.md), without modifying the original builder.
108
+
109
+
`ComposableEnumerable<T>` lets you decide how new API arguments should be combined with existing ones. You can choose to append, overwrite, or apply other strategies based on your needs.
110
+
111
+
If a module applies default commands and you need to override or remove them entirely, you can do this e.g. by explicitly resetting the command list:
Using `OverwriteEnumerable<string>(Array.Empty<string>())` removes all default command configurations. This is useful when you want full control over the PostgreSQL startup or when the default configurations do not match your requirements.
129
+
130
+
!!!tip
131
+
132
+
You can create your own `ComposableEnumerable<T>` implementation to control exactly how configuration values are composed or modified.
133
+
100
134
## Examples
101
135
102
136
An NGINX container that binds the HTTP port to a random host port and hosts static content. The example connects to the web server and checks the HTTP status code.
Testcontainers provides two distinct strategies for waiting until a TCP port becomes available, each serving different purposes depending on your testing needs.
57
+
58
+
### Wait until an internal TCP port is available
59
+
60
+
`UntilInternalTcpPortIsAvailable(int)` checks if a service inside the container is listening on the specified port by testing connectivity from within the container itself. This strategy verifies that your application or service has actually started and is ready to accept connections.
61
+
62
+
```csharp
63
+
_=Wait.ForUnixContainer()
64
+
.UntilInternalTcpPortIsAvailable(8080);
65
+
```
66
+
67
+
!!!note
68
+
69
+
Just because a service is listening on the internal TCP port does not necessarily mean it is fully ready to handle requests. Often, wait strategies such as checking for specific log messages or verifying a health endpoint provide more reliable confirmation that the service is operational.
70
+
71
+
### Wait until an external TCP port is available
72
+
73
+
`UntilExternalTcpPortIsAvailable(int)` checks if the port is accessible from the test host to the container. This verifies that the port mapping has been established and the port is reachable externally.
74
+
75
+
```csharp
76
+
_=Wait.ForUnixContainer()
77
+
.UntilExternalTcpPortIsAvailable(8080);
78
+
```
79
+
80
+
!!!note
81
+
82
+
External TCP port availability doesn't guarantee that the actual service inside the container is ready to handle requests. It only confirms that the port mapping is established and a connection can be made to the host-side proxy.
83
+
54
84
## Wait until the container is healthy
55
85
56
86
If the Docker image supports Dockers's [HEALTHCHECK][docker-docs-healthcheck] feature, like the following configuration:
0 commit comments