Skip to content

Commit c4af7d6

Browse files
committed
Merge pull request #46974 from quaff
* pr/46974: Polish "Create service connections for image with registry host and without project" Create service connections for image with registry host and without project Closes gh-46974
2 parents fafd0bb + a6afc39 commit c4af7d6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/ConnectionNamePredicate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* {@link Predicate} that matches against connection name.
3030
*
3131
* @author Phillip Webb
32+
* @author Yanming Zhou
3233
*/
3334
class ConnectionNamePredicate implements Predicate<DockerComposeConnectionSource> {
3435

@@ -47,7 +48,7 @@ public boolean test(DockerComposeConnectionSource source) {
4748

4849
private String getActual(RunningService service) {
4950
String label = service.labels().get("org.springframework.boot.service-connection");
50-
return (label != null) ? asCanonicalName(label) : service.image().getName();
51+
return asCanonicalName((label != null) ? label : service.image().getName());
5152
}
5253

5354
private String asCanonicalName(String name) {

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/ConnectionNamePredicateTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* Tests for {@link ConnectionNamePredicate}.
3333
*
3434
* @author Phillip Webb
35+
* @author Yanming Zhou
3536
*/
3637
class ConnectionNamePredicateTests {
3738

@@ -60,10 +61,15 @@ void organization() {
6061

6162
@Test
6263
void customDomain() {
64+
assertThat(predicateOf("redis")).accepts(sourceOf("internalhost:8080/redis"));
6365
assertThat(predicateOf("redis")).accepts(sourceOf("internalhost:8080/library/redis"));
66+
assertThat(predicateOf("redis")).accepts(sourceOf("myhost.com/redis"));
6467
assertThat(predicateOf("redis")).accepts(sourceOf("myhost.com/library/redis"));
6568
assertThat(predicateOf("redis")).accepts(sourceOf("myhost.com:8080/library/redis"));
66-
assertThat(predicateOf("redis")).rejects(sourceOf("internalhost:8080/redis"));
69+
assertThat(predicateOf("openzipkin/zipkin")).rejects(sourceOf("myhost.com:8080/zipkin"));
70+
assertThat(predicateOf("openzipkin/zipkin")).rejects(sourceOf("myhost.com:8080/library/zipkin"));
71+
assertThat(predicateOf("openzipkin/zipkin")).accepts(sourceOf("myhost.com:8080/openzipkin/zipkin"));
72+
assertThat(predicateOf("postgres")).accepts(sourceOf("docker.my-company.com/postgres:latest"));
6773
}
6874

6975
@Test

0 commit comments

Comments
 (0)