mirror of https://github.com/docker/compose.git
Convert `cascade_stop_test.go` into a cucumber feature `stop.feature`
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
parent
15ebff00b1
commit
a7476c8eeb
|
@ -74,16 +74,18 @@ func setup(s *godog.ScenarioContext) {
|
||||||
})
|
})
|
||||||
|
|
||||||
s.Step(`^a compose file$`, th.setComposeFile)
|
s.Step(`^a compose file$`, th.setComposeFile)
|
||||||
s.Step(`^I run "compose ([^"]*)"$`, th.runComposeCommand)
|
s.Step(`^I run "compose (.*)"$`, th.runComposeCommand)
|
||||||
s.Step(`service "([^"]*)" is "([^"]*)"$`, th.serviceIsStatus)
|
s.Step(`service "(.*)" is "(.*)"$`, th.serviceIsStatus)
|
||||||
s.Step(`output contains "([^"]*)"$`, th.outputContains)
|
s.Step(`output contains "(.*)"$`, th.outputContains)
|
||||||
|
s.Step(`exit code is (\d+)$`, th.exitCodeIs)
|
||||||
}
|
}
|
||||||
|
|
||||||
type testHelper struct {
|
type testHelper struct {
|
||||||
T *testing.T
|
T *testing.T
|
||||||
ComposeFile string
|
ComposeFile string
|
||||||
CommandOutput string
|
CommandOutput string
|
||||||
CLI *e2e.CLI
|
CommandExitCode int
|
||||||
|
CLI *e2e.CLI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (th *testHelper) serviceIsStatus(service, status string) error {
|
func (th *testHelper) serviceIsStatus(service, status string) error {
|
||||||
|
@ -103,16 +105,21 @@ func (th *testHelper) outputContains(substring string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (th *testHelper) exitCodeIs(exitCode int) error {
|
||||||
|
if exitCode != th.CommandExitCode {
|
||||||
|
return fmt.Errorf("Wrong exit code: %d expected: %d", th.CommandExitCode, exitCode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (th *testHelper) runComposeCommand(command string) error {
|
func (th *testHelper) runComposeCommand(command string) error {
|
||||||
commandArgs := []string{"-f", "-"}
|
commandArgs := []string{"-f", "-"}
|
||||||
commandArgs = append(commandArgs, strings.Split(command, " ")...)
|
commandArgs = append(commandArgs, strings.Split(command, " ")...)
|
||||||
cmd := th.CLI.NewDockerComposeCmd(th.T, commandArgs...)
|
cmd := th.CLI.NewDockerComposeCmd(th.T, commandArgs...)
|
||||||
cmd.Stdin = strings.NewReader(th.ComposeFile)
|
cmd.Stdin = strings.NewReader(th.ComposeFile)
|
||||||
res := icmd.RunCmd(cmd)
|
res := icmd.RunCmd(cmd)
|
||||||
if res.Error != nil {
|
|
||||||
return fmt.Errorf("compose up failed with error: %s\noutput: %s", res.Error, res.Combined())
|
|
||||||
}
|
|
||||||
th.CommandOutput = res.Combined()
|
th.CommandOutput = res.Combined()
|
||||||
|
th.CommandExitCode = res.ExitCode
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
Feature: Down
|
||||||
|
|
||||||
|
Scenario: No resources to remove
|
||||||
|
When I run "compose down"
|
||||||
|
Then the output contains "Warning: No resource found to remove for project "no_resources_to_remove""
|
|
@ -0,0 +1,30 @@
|
||||||
|
Feature: Stop
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given a compose file
|
||||||
|
"""
|
||||||
|
services:
|
||||||
|
should_fail:
|
||||||
|
image: alpine
|
||||||
|
command: ls /does_not_exist
|
||||||
|
sleep: # will be killed
|
||||||
|
image: alpine
|
||||||
|
command: ping localhost
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: Cascade stop
|
||||||
|
When I run "compose up --abort-on-container-exit"
|
||||||
|
Then the output contains "should_fail-1 exited with code 1"
|
||||||
|
And the output contains "Aborting on container exit..."
|
||||||
|
And the exit code is 1
|
||||||
|
|
||||||
|
Scenario: Exit code from
|
||||||
|
When I run "compose up --exit-code-from sleep"
|
||||||
|
Then the output contains "should_fail-1 exited with code 1"
|
||||||
|
And the output contains "Aborting on container exit..."
|
||||||
|
And the exit code is 137
|
||||||
|
|
||||||
|
Scenario: Exit code from unknown service
|
||||||
|
When I run "compose up --exit-code-from unknown"
|
||||||
|
Then the output contains "no such service: unknown"
|
||||||
|
And the exit code is 1
|
Loading…
Reference in New Issue