mirror of
https://github.com/docker/compose.git
synced 2026-10-12 02:13:08 +00:00
fix: wait rejects dry-run with a clear error
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 <[email protected]>
This commit is contained in:
committed by
Nicolas De loof
parent
8009372602
commit
dc62a5d153
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user