Improve error when Docker Compose file not found

Fixes gh-35383
This commit is contained in:
Scott Frederick
2023-05-10 13:26:59 -05:00
parent f911b85f64
commit 8377306668
3 changed files with 30 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.docker.compose.lifecycle;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
@@ -42,6 +43,7 @@ import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
@@ -54,6 +56,7 @@ import static org.mockito.Mockito.never;
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
*/
class DockerComposeLifecycleManagerTests {
@@ -113,6 +116,24 @@ class DockerComposeLifecycleManagerTests {
then(this.dockerCompose).should(never()).hasDefinedServices();
}
@Test
void startWhenComposeFileNotFoundThrowsException() {
DockerComposeLifecycleManager manager = new DockerComposeLifecycleManager(new File("."),
this.applicationContext, null, this.shutdownHandlers, this.properties, this.eventListeners,
this.skipCheck, this.serviceReadinessChecks);
assertThatIllegalStateException().isThrownBy(manager::start)
.withMessageContaining(Paths.get(".").toAbsolutePath().toString());
}
@Test
void startWhenComposeFileNotFoundAndWorkingDirectoryNullThrowsException() {
DockerComposeLifecycleManager manager = new DockerComposeLifecycleManager(null, this.applicationContext, null,
this.shutdownHandlers, this.properties, this.eventListeners, this.skipCheck,
this.serviceReadinessChecks);
assertThatIllegalStateException().isThrownBy(manager::start)
.withMessageContaining(Paths.get(".").toAbsolutePath().toString());
}
@Test
void startWhenInTestDoesNotStart() {
given(this.skipCheck.shouldSkip(any(), any())).willReturn(true);