Forráskód Böngészése

Merge pull request #9440 from ndeloof/down_error

compose down exit=0 if nothing to remove
Guillaume Lours 3 éve
szülő
commit
2f47e4582c
2 módosított fájl, 36 hozzáadás és 2 törlés
  1. 2 2
      pkg/compose/down.go
  2. 34 0
      pkg/e2e/compose_down_test.go

+ 2 - 2
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
 	}
 

+ 34 - 0
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"`})
+	})
+}