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:
Guillaume Lours
2026-09-30 14:47:16 +02:00
committed by Nicolas De loof
parent 8009372602
commit dc62a5d153
2 changed files with 19 additions and 0 deletions
+7
View File
@@ -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
+12
View File
@@ -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.