cascade_stop_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package e2e
  14. import (
  15. "testing"
  16. "gotest.tools/v3/icmd"
  17. )
  18. func TestCascadeStop(t *testing.T) {
  19. c := NewParallelE2eCLI(t, binDir)
  20. const projectName = "e2e-cascade-stop"
  21. t.Run("abort-on-container-exit", func(t *testing.T) {
  22. res := c.RunDockerOrExitError("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--abort-on-container-exit")
  23. res.Assert(t, icmd.Expected{ExitCode: 1, Out: `should_fail-1 exited with code 1`})
  24. res.Assert(t, icmd.Expected{ExitCode: 1, Out: `Aborting on container exit...`})
  25. })
  26. t.Run("exit-code-from", func(t *testing.T) {
  27. res := c.RunDockerOrExitError("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--exit-code-from=sleep")
  28. res.Assert(t, icmd.Expected{ExitCode: 137, Out: `should_fail-1 exited with code 1`})
  29. res.Assert(t, icmd.Expected{ExitCode: 137, Out: `Aborting on container exit...`})
  30. })
  31. t.Run("exit-code-from unknown", func(t *testing.T) {
  32. res := c.RunDockerOrExitError("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--exit-code-from=unknown")
  33. res.Assert(t, icmd.Expected{ExitCode: 1, Err: `no such service: unknown`})
  34. })
  35. t.Run("down", func(t *testing.T) {
  36. _ = c.RunDockerCmd("compose", "--project-name", projectName, "down")
  37. })
  38. }