Skip to content

Commit 7a3393c

Browse files
committed
Polish "Add failure analysis for invalid Docker environments"
See spring-projectsgh-47797
1 parent c914f64 commit 7a3393c

File tree

4 files changed

+7
-41
lines changed

4 files changed

+7
-41
lines changed

core/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/diagnostics/package-info.java

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.testcontainers.diagnostics;
17+
package org.springframework.boot.testcontainers.lifecycle;
1818

1919
import org.jspecify.annotations.Nullable;
2020

@@ -23,9 +23,11 @@
2323
import org.springframework.util.StringUtils;
2424

2525
/**
26-
* Failure analyzer for the Docker environment wasn't found.
26+
* A {@code FailureAnalyzer} that performs analysis of failures caused by Testcontainers
27+
* not finding a valid Docker environment.
2728
*
2829
* @author Dmytro Nosan
30+
* @author Stephane Nicoll
2931
*/
3032
class DockerEnvironmentNotFoundFailureAnalyzer extends AbstractFailureAnalyzer<IllegalStateException> {
3133

@@ -41,14 +43,10 @@ class DockerEnvironmentNotFoundFailureAnalyzer extends AbstractFailureAnalyzer<I
4143

4244
@Override
4345
protected @Nullable FailureAnalysis analyze(Throwable rootFailure, IllegalStateException cause) {
44-
if (isDockerEnvironmentNotFoundError(cause)) {
46+
if (StringUtils.hasText(cause.getMessage()) && cause.getMessage().contains(EXPECTED_MESSAGE)) {
4547
return new FailureAnalysis(DESCRIPTION, ACTION, cause);
4648
}
4749
return null;
4850
}
4951

50-
private boolean isDockerEnvironmentNotFoundError(IllegalStateException cause) {
51-
return StringUtils.hasText(cause.getMessage()) && cause.getMessage().contains(EXPECTED_MESSAGE);
52-
}
53-
5452
}

core/spring-boot-testcontainers/src/main/resources/META-INF/spring.factories

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ org.springframework.boot.testcontainers.service.connection.ServiceConnectionCont
88

99
# Failure Analyzers
1010
org.springframework.boot.diagnostics.FailureAnalyzer=\
11-
org.springframework.boot.testcontainers.diagnostics.DockerEnvironmentNotFoundFailureAnalyzer
11+
org.springframework.boot.testcontainers.lifecycle.DockerEnvironmentNotFoundFailureAnalyzer
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.testcontainers.diagnostics;
17+
package org.springframework.boot.testcontainers.lifecycle;
1818

1919
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.boot.diagnostics.FailureAnalysis;
22-
import org.springframework.boot.diagnostics.FailureAnalyzer;
23-
import org.springframework.core.io.support.SpringFactoriesLoader;
2422

2523
import static org.assertj.core.api.Assertions.assertThat;
2624

@@ -59,11 +57,4 @@ void shouldReturnNullWhenMessageIsNull() {
5957
assertThat(analysis).isNull();
6058
}
6159

62-
@Test
63-
void shouldBeRegisteredInSpringFactories() {
64-
assertThat(SpringFactoriesLoader.forDefaultResourceLocation(getClass().getClassLoader())
65-
.load(FailureAnalyzer.class, (factoryType, factoryImplementationName, failure) -> {
66-
})).anyMatch(DockerEnvironmentNotFoundFailureAnalyzer.class::isInstance);
67-
}
68-
6960
}

0 commit comments

Comments
 (0)