mirror of
https://github.com/docker/compose.git
synced 2026-11-21 07:30:30 +00:00
fix: wait rejects dry-run with a clear error
Some checks failed
ci / validate (lint) (push) Waiting to run
ci / validate (relay-lint) (push) Waiting to run
ci / validate (relay-test) (push) Waiting to run
ci / validate (validate-docs) (push) Waiting to run
ci / validate (validate-go-mod) (push) Waiting to run
ci / validate (validate-headers) (push) Waiting to run
ci / validate (validate-mocks) (push) Waiting to run
ci / binary (push) Waiting to run
ci / binary-finalize (push) Blocked by required conditions
ci / bin-image-test (push) Waiting to run
ci / relay-image-test (push) Waiting to run
ci / test (push) Waiting to run
ci / e2e (plugin, oldstable, graphdriver) (push) Waiting to run
ci / e2e (standalone, oldstable, graphdriver) (push) Waiting to run
ci / e2e (plugin, stable, containerd) (push) Waiting to run
ci / e2e (plugin, stable, graphdriver) (push) Waiting to run
ci / e2e (standalone, stable, containerd) (push) Waiting to run
ci / e2e (standalone, stable, graphdriver) (push) Waiting to run
ci / coverage (push) Blocked by required conditions
ci / release (push) Blocked by required conditions
merge / bin-image-prepare (push) Waiting to run
merge / bin-image (push) Blocked by required conditions
merge / relay-image (push) Waiting to run
merge / module-image (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
zizmor / zizmor (push) Waiting to run
docs-upstream / docs-yaml (push) Has been cancelled
docs-upstream / validate (push) Has been cancelled
Some checks failed
ci / validate (lint) (push) Waiting to run
ci / validate (relay-lint) (push) Waiting to run
ci / validate (relay-test) (push) Waiting to run
ci / validate (validate-docs) (push) Waiting to run
ci / validate (validate-go-mod) (push) Waiting to run
ci / validate (validate-headers) (push) Waiting to run
ci / validate (validate-mocks) (push) Waiting to run
ci / binary (push) Waiting to run
ci / binary-finalize (push) Blocked by required conditions
ci / bin-image-test (push) Waiting to run
ci / relay-image-test (push) Waiting to run
ci / test (push) Waiting to run
ci / e2e (plugin, oldstable, graphdriver) (push) Waiting to run
ci / e2e (standalone, oldstable, graphdriver) (push) Waiting to run
ci / e2e (plugin, stable, containerd) (push) Waiting to run
ci / e2e (plugin, stable, graphdriver) (push) Waiting to run
ci / e2e (standalone, stable, containerd) (push) Waiting to run
ci / e2e (standalone, stable, graphdriver) (push) Waiting to run
ci / coverage (push) Blocked by required conditions
ci / release (push) Blocked by required conditions
merge / bin-image-prepare (push) Waiting to run
merge / bin-image (push) Blocked by required conditions
merge / relay-image (push) Waiting to run
merge / module-image (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
zizmor / zizmor (push) Waiting to run
docs-upstream / docs-yaml (push) Has been cancelled
docs-upstream / validate (push) Has been cancelled
Wait has no real container to observe in dry-run: getContainers falls back to the live daemon and finds nothing, so the command failed with a misleading "no containers for project" error instead of signaling upfront that the operation doesn't apply under simulation. Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
This commit is contained in:
parent
8009372602
commit
dc62a5d153
2 changed files with 19 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ package compose
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/moby/moby/client"
|
||||
|
|
@ -27,6 +28,12 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Wait(ctx context.Context, projectName string, options api.WaitOptions) (int64, error) {
|
||||
if s.dryRun {
|
||||
// dry-run never starts a real container, so there is nothing for
|
||||
// wait to observe: refuse upfront instead of racing the fake API
|
||||
// client into a misleading "no containers" error.
|
||||
return 0, errors.New("wait is not supported in dry-run mode")
|
||||
}
|
||||
containers, err := s.getContainers(ctx, projectName, oneOffInclude, false, options.Services...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
|||
|
|
@ -82,6 +82,18 @@ func TestWait_NoContainersAtAll(t *testing.T) {
|
|||
assert.Equal(t, *allCalls, 1)
|
||||
}
|
||||
|
||||
// TestWait_DryRunNotSupported: dry-run refuses immediately, without
|
||||
// listing containers.
|
||||
func TestWait_DryRunNotSupported(t *testing.T) {
|
||||
tested, _, runningCalls, allCalls := waitTestService(t, nil, nil)
|
||||
tested.(*composeService).dryRun = true
|
||||
|
||||
_, err := tested.Wait(t.Context(), "proj", api.WaitOptions{})
|
||||
assert.ErrorContains(t, err, "not supported in dry-run mode")
|
||||
assert.Equal(t, *runningCalls, 0)
|
||||
assert.Equal(t, *allCalls, 0)
|
||||
}
|
||||
|
||||
// TestWait_RunningContainersSkipFallback: with a running container to
|
||||
// observe, the fallback listing never runs — a stale exited one-off cannot
|
||||
// short-circuit the wait.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue