From a7476c8eeb9b43f22cf40905a07d622738b0b6a1 Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Mon, 12 Sep 2022 17:38:43 -0400 Subject: [PATCH] Convert `cascade_stop_test.go` into a cucumber feature `stop.feature` Signed-off-by: Laura Brehm --- pkg/e2e/cucumber/cucumber_test.go | 27 +++++++++++++++++---------- pkg/e2e/cucumber/down.feature | 5 +++++ pkg/e2e/cucumber/stop.feature | 30 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 pkg/e2e/cucumber/down.feature create mode 100644 pkg/e2e/cucumber/stop.feature diff --git a/pkg/e2e/cucumber/cucumber_test.go b/pkg/e2e/cucumber/cucumber_test.go index d32cf5e5..ad09c87d 100644 --- a/pkg/e2e/cucumber/cucumber_test.go +++ b/pkg/e2e/cucumber/cucumber_test.go @@ -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 } diff --git a/pkg/e2e/cucumber/down.feature b/pkg/e2e/cucumber/down.feature new file mode 100644 index 00000000..1f53d5d5 --- /dev/null +++ b/pkg/e2e/cucumber/down.feature @@ -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"" diff --git a/pkg/e2e/cucumber/stop.feature b/pkg/e2e/cucumber/stop.feature new file mode 100644 index 00000000..46b33732 --- /dev/null +++ b/pkg/e2e/cucumber/stop.feature @@ -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