cascade_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //go:build !windows
  2. /*
  3. Copyright 2022 Docker Compose CLI authors
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package e2e
  15. import (
  16. "strings"
  17. "testing"
  18. "gotest.tools/v3/assert"
  19. )
  20. func TestCascadeStop(t *testing.T) {
  21. c := NewCLI(t)
  22. const projectName = "compose-e2e-cascade-stop"
  23. t.Cleanup(func() {
  24. c.RunDockerComposeCmd(t, "--project-name", projectName, "down")
  25. })
  26. res := c.RunDockerComposeCmd(t, "-f", "./fixtures/cascade/compose.yaml", "--project-name", projectName,
  27. "up", "--abort-on-container-exit")
  28. assert.Assert(t, strings.Contains(res.Combined(), "exit-1 exited with code 0"), res.Combined())
  29. // no --exit-code-from, so this is not an error
  30. assert.Equal(t, res.ExitCode, 0)
  31. }
  32. func TestCascadeFail(t *testing.T) {
  33. c := NewCLI(t)
  34. const projectName = "compose-e2e-cascade-fail"
  35. t.Cleanup(func() {
  36. c.RunDockerComposeCmd(t, "--project-name", projectName, "down")
  37. })
  38. res := c.RunDockerComposeCmdNoCheck(t, "-f", "./fixtures/cascade/compose.yaml", "--project-name", projectName,
  39. "up", "--abort-on-container-failure")
  40. assert.Assert(t, strings.Contains(res.Combined(), "exit-1 exited with code 0"), res.Combined())
  41. assert.Assert(t, strings.Contains(res.Combined(), "fail-1 exited with code 111"), res.Combined())
  42. // failing exit code should be propagated
  43. assert.Equal(t, res.ExitCode, 111)
  44. }