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

This commit is contained in:
Guillaume Tardif 2020-07-03 10:03:46 +02:00
parent ae76e0cf27
commit 6b74716490
3 changed files with 16 additions and 2 deletions

View File

@ -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
}

View File

@ -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))

View File

@ -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"