From 6b74716490acbb01acc7d8637f41fcc3f4383ec1 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 3 Jul 2020 10:03:46 +0200 Subject: [PATCH] Specific error message when user tries to remove one container from an ACI compose application, mentioning the name of the compose application and that user should use compose down --- azure/backend.go | 6 +++++- azure/backend_test.go | 9 +++++++++ example/backend.go | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/azure/backend.go b/azure/backend.go index cd3a4654e..5d1f9213d 100644 --- a/azure/backend.go +++ b/azure/backend.go @@ -258,7 +258,11 @@ func (cs *aciContainerService) Logs(ctx context.Context, containerName string, r } func (cs *aciContainerService) Delete(ctx context.Context, containerID string, _ bool) error { - cg, err := deleteACIContainerGroup(ctx, cs.ctx, containerID) + groupName, containerName := getGroupAndContainerName(containerID) + if groupName != containerID { + return errors.New(fmt.Sprintf(`cannot delete service "%s" from compose app "%s", you must delete the entire compose app with docker compose down`, containerName, groupName)) + } + cg, err := deleteACIContainerGroup(ctx, cs.ctx, groupName) if err != nil { return err } diff --git a/azure/backend_test.go b/azure/backend_test.go index 6f50678df..7b17f704f 100644 --- a/azure/backend_test.go +++ b/azure/backend_test.go @@ -17,6 +17,7 @@ package azure import ( + "context" "testing" "github.com/stretchr/testify/suite" @@ -42,6 +43,14 @@ func (suite *BackendSuiteTest) TestGetContainerName() { Expect(container).To(Equal("service1")) } +func (suite *BackendSuiteTest) TestErrorMessageDeletingContainerFromComposeApplication() { + service := aciContainerService{} + err := service.Delete(context.TODO(), "compose-app_service1", false) + + Expect(err).NotTo(BeNil()) + Expect(err.Error()).To(Equal("cannot delete service \"service1\" from compose app \"compose-app\", you must delete the entire compose app with docker compose down")) +} + func TestBackendSuite(t *testing.T) { RegisterTestingT(t) suite.Run(t, new(BackendSuiteTest)) diff --git a/example/backend.go b/example/backend.go index 076b4087f..c5da8bf1e 100644 --- a/example/backend.go +++ b/example/backend.go @@ -22,9 +22,10 @@ import ( "context" "errors" "fmt" - "github.com/compose-spec/compose-go/cli" "io" + "github.com/compose-spec/compose-go/cli" + "github.com/docker/api/context/cloud" "github.com/docker/api/backend"