(t *testing.T)
| 251 | } |
| 252 | |
| 253 | func TestPreStartHookMidSequenceFailure(t *testing.T) { |
| 254 | c := NewParallelCLI(t) |
| 255 | const ( |
| 256 | projectName = "hooks-pre-start-mid-failure" |
| 257 | composeFile = "fixtures/pre_start/mid-failure/compose.yaml" |
| 258 | ) |
| 259 | |
| 260 | t.Cleanup(func() { |
| 261 | c.RunDockerComposeCmd(t, "-f", composeFile, "--project-name", projectName, "down", "-v", "--remove-orphans", "-t", "0") |
| 262 | }) |
| 263 | |
| 264 | // Hook 0 succeeds; hook 1 exits with code 17. up must fail. |
| 265 | res := c.RunDockerComposeCmdNoCheck(t, "-f", composeFile, "--project-name", projectName, "up", "-d") |
| 266 | res.Assert(t, icmd.Expected{ExitCode: 1}) |
| 267 | |
| 268 | // Error must point at hook index 1 (not 0) and report exit code 17. |
| 269 | assert.Assert(t, strings.Contains(res.Combined(), "pre_start[1]"), "expected pre_start[1] in output, got: %s", res.Combined()) |
| 270 | assert.Assert(t, strings.Contains(res.Combined(), "17"), "expected exit code 17 in output, got: %s", res.Combined()) |
| 271 | |
| 272 | // Hook 0 must have run before hook 1 failed: the file must contain "ran-0". |
| 273 | probe := c.RunDockerCmd(t, "run", "--rm", "-v", projectName+"_data:/mnt", "alpine", "cat", "/mnt/hooks.txt") |
| 274 | assert.Assert(t, strings.Contains(probe.Stdout(), "ran-0"), "expected hook 0 output in volume, got: %s", probe.Stdout()) |
| 275 | |
| 276 | // The service container must exist but not be running. |
| 277 | ps := c.RunDockerCmd(t, "ps", "-a", "--filter", "label=com.docker.compose.project="+projectName, "--format", "{{.Names}} {{.State}}") |
| 278 | assert.Assert(t, strings.Contains(ps.Combined(), "sample"), "expected service container in ps output, got: %s", ps.Combined()) |
| 279 | assert.Assert(t, !strings.Contains(ps.Combined(), "running"), "service container must not be running, got: %s", ps.Combined()) |
| 280 | } |
| 281 | |
| 282 | func TestPreStartHookSequentialOrder(t *testing.T) { |
| 283 | c := NewParallelCLI(t) |
nothing calls this directly
no test coverage detected