Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/stop/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ func TestStopCommand(t *testing.T) {

func TestStopServices(t *testing.T) {
t.Run("stops all services", func(t *testing.T) {
containers := []container.Summary{{ID: "c1", State: "running"}, {ID: "c2"}}
containers := []container.Summary{
{ID: "c1", State: "running"},
{ID: "c2", State: "exited"},
}
// Setup mock docker
require.NoError(t, apitest.MockDocker(utils.Docker))
defer gock.OffAll()
Expand All @@ -174,6 +177,9 @@ func TestStopServices(t *testing.T) {
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/" + containers[0].ID + "/stop").
Reply(http.StatusOK)
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/" + containers[1].ID + "/stop").
Reply(http.StatusNotModified)
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/prune").
Reply(http.StatusOK).
Expand Down
6 changes: 2 additions & 4 deletions internal/utils/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ func DockerRemoveAll(ctx context.Context, w io.Writer, projectId string) error {
// Gracefully shutdown containers
var ids []string
for _, c := range containers {
if c.State == "running" {
ids = append(ids, c.ID)
}
ids = append(ids, c.ID)
}
result := WaitAll(ids, func(id string) error {
if err := Docker.ContainerStop(ctx, id, container.StopOptions{}); err != nil {
if err := Docker.ContainerStop(ctx, id, container.StopOptions{}); err != nil && !errdefs.IsNotModified(err) {
return errors.Errorf("failed to stop container: %w", err)
}
return nil
Expand Down
Loading