Skip to content

Commit 2f47e45

Browse files
authored
Merge pull request docker#9440 from ndeloof/down_error
compose down exit=0 if nothing to remove
2 parents 4cebef1 + 78b0676 commit 2f47e45

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pkg/compose/down.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
9090
}
9191

9292
if !resourceToRemove && len(ops) == 0 {
93-
w.Event(progress.NewEvent(projectName, progress.Done, "Warning: No resource found to remove"))
93+
fmt.Fprintf(s.stderr(), "Warning: No resource found to remove for project %q.\n", projectName)
9494
}
9595

9696
eg, _ := errgroup.WithContext(ctx)
@@ -239,7 +239,7 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
239239
func (s *composeService) getProjectWithResources(ctx context.Context, containers Containers, projectName string) (*types.Project, error) {
240240
containers = containers.filter(isNotOneOff)
241241
project, err := s.projectFromName(containers, projectName)
242-
if err != nil {
242+
if err != nil && !api.IsNotFoundError(err) {
243243
return nil, err
244244
}
245245

pkg/e2e/compose_down_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"testing"
21+
22+
"gotest.tools/v3/icmd"
23+
)
24+
25+
func TestDown(t *testing.T) {
26+
c := NewParallelE2eCLI(t, binDir)
27+
28+
const projectName = "e2e-down"
29+
30+
t.Run("no resource to remove", func(t *testing.T) {
31+
res := c.RunDockerOrExitError("compose", "--project-name", projectName, "down")
32+
res.Assert(t, icmd.Expected{ExitCode: 0, Err: `No resource found to remove for project "e2e-down"`})
33+
})
34+
}

0 commit comments

Comments
 (0)