Add log message if Docker Compose services are already running

Closes gh-38398
This commit is contained in:
Moritz Halbritter
2023-12-05 14:02:16 +01:00
parent 24886eae64
commit 3f29c7f84f
2 changed files with 31 additions and 7 deletions

View File

@@ -29,6 +29,7 @@ import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.aot.AotDetector;
@@ -38,6 +39,8 @@ import org.springframework.boot.docker.compose.core.DockerCompose;
import org.springframework.boot.docker.compose.core.DockerComposeFile;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Readiness.Wait;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.support.GenericApplicationContext;
@@ -59,6 +62,7 @@ import static org.mockito.Mockito.never;
* @author Phillip Webb
* @author Scott Frederick
*/
@ExtendWith(OutputCaptureExtension.class)
class DockerComposeLifecycleManagerTests {
@TempDir
@@ -365,6 +369,21 @@ class DockerComposeLifecycleManagerTests {
assertThat(event.getRunningServices()).isEqualTo(this.runningServices);
}
@Test
void shouldLogIfServicesAreAlreadyRunning(CapturedOutput output) {
setUpRunningServices();
this.lifecycleManager.start();
assertThat(output).contains("There are already Docker Compose services running, skipping startup");
}
@Test
void shouldNotLogIfThereAreNoServicesRunning(CapturedOutput output) {
given(this.dockerCompose.hasDefinedServices()).willReturn(true);
given(this.dockerCompose.getRunningServices()).willReturn(Collections.emptyList());
this.lifecycleManager.start();
assertThat(output).doesNotContain("There are already Docker Compose services running, skipping startup");
}
private void setUpRunningServices() {
setUpRunningServices(true);
}