Skip to content

Commit

Permalink
feat: Allow the container working directory to be specified (#1899)
Browse files Browse the repository at this point in the history
* feat: Allow the container working directory to be specified in ContainerRequest

* move WorkingDir field position in ContainerRequest struct
  • Loading branch information
fhke committed Nov 6, 2023
1 parent ef7e6bf commit 5562dbc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type ContainerRequest struct {
WaitingFor wait.Strategy
Name string // for specifying container name
Hostname string
WorkingDir string // specify the working directory of the container
ExtraHosts []string // Deprecated: Use HostConfigModifier instead
Privileged bool // For starting privileged container
Networks []string // for specifying network names
Expand Down
1 change: 1 addition & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
Cmd: req.Cmd,
Hostname: req.Hostname,
User: req.User,
WorkingDir: req.WorkingDir,
}

hostConfig := &container.HostConfig{
Expand Down
28 changes: 28 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,34 @@ func TestEntrypoint(t *testing.T) {
terminateContainerOnEnd(t, ctx, c)
}

func TestWorkingDir(t *testing.T) {
/*
print the current working directory to ensure that
we can specify working directory in the
ContainerRequest and it will be used for the container
*/

ctx := context.Background()

req := ContainerRequest{
Image: "docker.io/alpine",
WaitingFor: wait.ForAll(
wait.ForLog("/var/tmp/test"),
),
Entrypoint: []string{"pwd"},
WorkingDir: "/var/tmp/test",
}

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

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

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

0 comments on commit 5562dbc

Please sign in to comment.