Skip to content

Commit

Permalink
docs: document skip internal check
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Aug 12, 2024
1 parent 096b855 commit e5411a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions docs/features/wait/host_port.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The host-port wait strategy will check if the container is listening to a specif
- alternatively, wait for the lowest exposed port in the container.
- the startup timeout to be used, default is 60 seconds.
- the poll interval to be used, default is 100 milliseconds.
- skip the internal check.

Variations on the HostPort wait strategy are supported, including:

Expand Down Expand Up @@ -39,3 +40,23 @@ req := ContainerRequest{
WaitingFor: wait.ForExposedPort(),
}
```

## Skipping the internal check

_Testcontainers for Go_ checks if the container is listening to the port internally before returning the control to the caller. For that it uses a shell command to check the port status:

<!--codeinclude-->
[Internal check](../../../wait/host_port.go) inside_block:buildInternalCheckCommand
<!--/codeinclude-->

But there are cases where this internal check is not needed, for example when a shell is not available in the container or
when the container doesn't bind the port internally until additional conditions are met.
In this case, the `wait.ForExposedPort.SkipInternalCheck` can be used to skip the internal check.

```golang
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
ExposedPorts: []string{"80/tcp", "9080/tcp"},
WaitingFor: wait.ForExposedPort().SkipInternalCheck(),
}
```
4 changes: 2 additions & 2 deletions wait/host_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func ForExposedPort() *HostPortStrategy {
return NewHostPortStrategy("")
}

// WithoutInternalCheck changes the host port strategy to skip the internal check,
// SkipInternalCheck changes the host port strategy to skip the internal check,
// which is useful when a shell is not available in the container or when the
// container doesn't bind the port internally until additional conditions are met.
func (hp *HostPortStrategy) WithoutInternalCheck() *HostPortStrategy {
func (hp *HostPortStrategy) SkipInternalCheck() *HostPortStrategy {
hp.skipInternalCheck = true

return hp
Expand Down

0 comments on commit e5411a7

Please sign in to comment.