From 167841daadd938bf6b00a6eb5f0336606b04c00b Mon Sep 17 00:00:00 2001 From: Ewa Czechowska Date: Sat, 4 Jan 2020 14:03:48 +0100 Subject: [PATCH] driver: docker-compose, action: run: fix a bug when handling a signal, when no default container --- CHANGELOG.md | 3 +++ docker_compose_driver.go | 5 ++++- docker_compose_driver_test.go | 6 ------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a053be..0723e51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ * Implemented Ctrl+C (SigInt) to work for action: run for both drivers (docker and docker-compose). The change in the run action for docker-compose driver is that now Dojo first explicitly invokes the pull action and then it invokes the run action. +* Driver: docker-compose, action: run: fix a bug when handling a signal. Previously, when default container was + not (yet) created, there was a panic. But, it may happen that the default container is not created while + other containers are created. From now on, Dojo will not panic and it will stop the other containers. ### 0.8.0 (2020-Jan-01) diff --git a/docker_compose_driver.go b/docker_compose_driver.go index a07b943..3efe0ad 100644 --- a/docker_compose_driver.go +++ b/docker_compose_driver.go @@ -528,6 +528,7 @@ func (dc DockerComposeDriver) HandleSignal(mergedConfig Config, runID string) in } defaultContainerID := dc.getDefaultContainerID(names) + // it may happen that the default container is not created, but other containers are es := dc.stop(mergedConfig, runID, defaultContainerID) dc.Logger.Log("info", "Stopping on signal finished") return es @@ -568,6 +569,7 @@ func (dc DockerComposeDriver) HandleMultipleSignal(mergedConfig Config, runID st } defaultContainerID := dc.getDefaultContainerID(names) + // it may happen that the default container is not created, but other containers are es := dc.kill(mergedConfig, runID, defaultContainerID) dc.Logger.Log("info", "Stopping on multiple signals finished") return es @@ -588,7 +590,8 @@ func (dc DockerComposeDriver) getDefaultContainerID(containersNames []string) st return contanerInfo.ID } } - panic(fmt.Errorf("default container not found. Were the containers created?")) + dc.Logger.Log("info", "Default container not found") + return "" } // example output of docker-compose ps: diff --git a/docker_compose_driver_test.go b/docker_compose_driver_test.go index 18a9b7b..ead9bae 100644 --- a/docker_compose_driver_test.go +++ b/docker_compose_driver_test.go @@ -531,15 +531,9 @@ func Test_getDefaultContainerID_notCreated(t *testing.T) { shellS := NewMockedShellServiceNotInteractive(logger) driver := NewDockerComposeDriver(shellS, fs, logger) - defer func() { - r := recover() - assert.Contains(t, r.(error).Error(), "default container not found. Were the containers created?") - }() - names := []string{} id := driver.getDefaultContainerID(names) assert.Equal(t, "", id) - t.Fatal("Expected panic") } func Test_checkContainerIsRunning(t *testing.T) {