Skip to content

Commit

Permalink
add test to reproduce the issue testcontainers#2543
Browse files Browse the repository at this point in the history
  • Loading branch information
Willian S. de Souza authored and wilsouza committed Jun 15, 2024
1 parent dd7d7a9 commit 76ab528
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,40 @@ func TestWorkingDir(t *testing.T) {
terminateContainerOnEnd(t, ctx, c)
}

func TestExposePortOnPostStartHook(t *testing.T) {
ctx := context.Background()
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForHTTP("/").WithStartupTimeout(10 * time.Second),
LifecycleHooks: []ContainerLifecycleHooks{
{
PostStarts: []ContainerHook{
func(ctx context.Context, c Container) error {
// fill inspect cache
_, err := c.Host(ctx)
require.NoError(t, err)

// get expose image port from inspect cache
_, err = c.MappedPort(ctx, "80/tcp")
require.NoError(t, err, "expected to get mapped port for 80/tcp")

return nil
},
},
},
},
}
nginxC, err := GenericContainer(ctx, GenericContainerRequest{
ProviderType: providerType,
ContainerRequest: req,
Started: true,
})

require.NoError(t, err)
terminateContainerOnEnd(t, ctx, nginxC)
}

func ExampleDockerProvider_CreateContainer() {
ctx := context.Background()
req := ContainerRequest{
Expand Down

0 comments on commit 76ab528

Please sign in to comment.