Convert `cascade_stop_test.go` into a cucumber feature `stop.feature`

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
Laura Brehm 2022-09-12 17:38:43 -04:00
parent 15ebff00b1
commit a7476c8eeb
No known key found for this signature in database
GPG Key ID: 526E3FC49260D47A
3 changed files with 52 additions and 10 deletions

View File

@ -74,16 +74,18 @@ func setup(s *godog.ScenarioContext) {
})
s.Step(`^a compose file$`, th.setComposeFile)
s.Step(`^I run "compose ([^"]*)"$`, th.runComposeCommand)
s.Step(`service "([^"]*)" is "([^"]*)"$`, th.serviceIsStatus)
s.Step(`output contains "([^"]*)"$`, th.outputContains)
s.Step(`^I run "compose (.*)"$`, th.runComposeCommand)
s.Step(`service "(.*)" is "(.*)"$`, th.serviceIsStatus)
s.Step(`output contains "(.*)"$`, th.outputContains)
s.Step(`exit code is (\d+)$`, th.exitCodeIs)
}
type testHelper struct {
T *testing.T
ComposeFile string
CommandOutput string
CLI *e2e.CLI
T *testing.T
ComposeFile string
CommandOutput string
CommandExitCode int
CLI *e2e.CLI
}
func (th *testHelper) serviceIsStatus(service, status string) error {
@ -103,16 +105,21 @@ func (th *testHelper) outputContains(substring string) error {
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 {
commandArgs := []string{"-f", "-"}
commandArgs = append(commandArgs, strings.Split(command, " ")...)
cmd := th.CLI.NewDockerComposeCmd(th.T, commandArgs...)
cmd.Stdin = strings.NewReader(th.ComposeFile)
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.CommandExitCode = res.ExitCode
return nil
}

View File

@ -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""

View File

@ -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