diff --git a/pkg/compose/down.go b/pkg/compose/down.go index 862cc7293..0130f5a58 100644 --- a/pkg/compose/down.go +++ b/pkg/compose/down.go @@ -90,7 +90,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options a } if !resourceToRemove && len(ops) == 0 { - w.Event(progress.NewEvent(projectName, progress.Done, "Warning: No resource found to remove")) + fmt.Fprintf(s.stderr(), "Warning: No resource found to remove for project %q.\n", projectName) } eg, _ := errgroup.WithContext(ctx) @@ -239,7 +239,7 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer func (s *composeService) getProjectWithResources(ctx context.Context, containers Containers, projectName string) (*types.Project, error) { containers = containers.filter(isNotOneOff) project, err := s.projectFromName(containers, projectName) - if err != nil { + if err != nil && !api.IsNotFoundError(err) { return nil, err } diff --git a/pkg/e2e/compose_down_test.go b/pkg/e2e/compose_down_test.go new file mode 100644 index 000000000..1f8eaebe5 --- /dev/null +++ b/pkg/e2e/compose_down_test.go @@ -0,0 +1,34 @@ +/* + Copyright 2020 Docker Compose CLI authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package e2e + +import ( + "testing" + + "gotest.tools/v3/icmd" +) + +func TestDown(t *testing.T) { + c := NewParallelE2eCLI(t, binDir) + + const projectName = "e2e-down" + + t.Run("no resource to remove", func(t *testing.T) { + res := c.RunDockerOrExitError("compose", "--project-name", projectName, "down") + res.Assert(t, icmd.Expected{ExitCode: 0, Err: `No resource found to remove for project "e2e-down"`}) + }) +}