Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions cmd/nerdctl/compose/compose_run_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,51 @@ services:
testCase.Run(t)
}

func TestComposeRunWithWorkdir(t *testing.T) {
const expectedOutput = "/tmp"

dockerComposeYAML := fmt.Sprintf(`
services:
alpine:
image: %s
entrypoint:
- pwd
`, testutil.CommonImage)

testCase := nerdtest.Setup()

testCase.Setup = func(data test.Data, helpers test.Helpers) {
composePath := data.Temp().Save(dockerComposeYAML, "compose.yaml")
projectName := filepath.Base(filepath.Dir(composePath))
t.Logf("projectName=%q", projectName)
}

testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
cmd := helpers.Command(
"compose",
"-f",
data.Temp().Path("compose.yaml"),
"run",
"--workdir",
"/tmp",
"--name",
data.Identifier(),
"alpine",
)
cmd.WithPseudoTTY()
return cmd
}

testCase.Expected = test.Expects(expect.ExitCodeSuccess, nil, expect.Contains(expectedOutput))

testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rm", "-f", "-v", data.Identifier())
helpers.Anyhow("compose", "-f", data.Temp().Path("compose.yaml"), "down", "-v")
}

testCase.Run(t)
}

func TestComposeRunWithLabel(t *testing.T) {
dockerComposeYAML := fmt.Sprintf(`
services:
Expand Down
2 changes: 1 addition & 1 deletion pkg/composer/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *Composer) Run(ctx context.Context, ro RunOptions) error {
}
}
if ro.WorkDir != "" {
c.project.WorkingDir = ro.WorkDir
targetSvc.WorkingDir = ro.WorkDir
}

// `compose run` command does not create any of the ports specified in the service configuration.
Expand Down
Loading