cascade_test.go 1.8 KB

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