Skip to content

Commit 0899e13

Browse files
committed
Fix environment variable keys for bitnami/postgresql
Signed-off-by: He Zean <realhezean@gmail.com>
1 parent cc49b30 commit 0899e13

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
class PostgresJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {
4040

4141
@DockerComposeTest(composeFile = "postgres-compose.yaml", image = TestImage.POSTGRESQL)
42-
void runCreatesConnectionDetails(JdbcConnectionDetails connectionDetails) {
42+
void runCreatesConnectionDetails(JdbcConnectionDetails connectionDetails) throws ClassNotFoundException {
4343
assertConnectionDetails(connectionDetails);
44+
checkDatabaseAccess(connectionDetails);
4445
}
4546

4647
@DockerComposeTest(composeFile = "postgres-with-trust-host-auth-method-compose.yaml", image = TestImage.POSTGRESQL)
@@ -53,8 +54,10 @@ void runCreatesConnectionDetailsThatCanAccessDatabaseWhenHostAuthMethodIsTrust(
5354
}
5455

5556
@DockerComposeTest(composeFile = "postgres-bitnami-compose.yaml", image = TestImage.BITNAMI_POSTGRESQL)
56-
void runWithBitnamiImageCreatesConnectionDetails(JdbcConnectionDetails connectionDetails) {
57+
void runWithBitnamiImageCreatesConnectionDetails(JdbcConnectionDetails connectionDetails)
58+
throws ClassNotFoundException {
5759
assertConnectionDetails(connectionDetails);
60+
checkDatabaseAccess(connectionDetails);
5861
}
5962

6063
@DockerComposeTest(composeFile = "postgres-application-name-compose.yaml", image = TestImage.POSTGRESQL)

spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PostgresR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests {
4343
@DockerComposeTest(composeFile = "postgres-compose.yaml", image = TestImage.POSTGRESQL)
4444
void runCreatesConnectionDetails(R2dbcConnectionDetails connectionDetails) {
4545
assertConnectionDetails(connectionDetails);
46+
checkDatabaseAccess(connectionDetails);
4647
}
4748

4849
@DockerComposeTest(composeFile = "postgres-with-trust-host-auth-method-compose.yaml", image = TestImage.POSTGRESQL)
@@ -59,6 +60,7 @@ void runCreatesConnectionDetailsThatCanAccessDatabaseWhenHostAuthMethodIsTrust(
5960
@DockerComposeTest(composeFile = "postgres-bitnami-compose.yaml", image = TestImage.BITNAMI_POSTGRESQL)
6061
void runWithBitnamiImageCreatesConnectionDetails(R2dbcConnectionDetails connectionDetails) {
6162
assertConnectionDetails(connectionDetails);
63+
checkDatabaseAccess(connectionDetails);
6264
}
6365

6466
@DockerComposeTest(composeFile = "postgres-application-name-compose.yaml", image = TestImage.POSTGRESQL)

spring-boot-project/spring-boot-docker-compose/src/dockerTest/resources/org/springframework/boot/docker/compose/service/connection/postgres/postgres-bitnami-compose.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ services:
44
ports:
55
- '5432'
66
environment:
7-
- 'POSTGRESQL_USER=myuser'
8-
- 'POSTGRESQL_DB=mydatabase'
7+
- 'POSTGRESQL_USERNAME=myuser'
8+
- 'POSTGRESQL_DATABASE=mydatabase'
99
- 'POSTGRESQL_PASSWORD=secret'

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
2929
* @author Phillip Webb
3030
* @author Scott Frederick
3131
* @author Sidmar Theodoro
32+
* @author He Zean
3233
*/
3334
class PostgresEnvironment {
3435

@@ -39,9 +40,9 @@ class PostgresEnvironment {
3940
private final String database;
4041

4142
PostgresEnvironment(Map<String, String> env) {
42-
this.username = env.getOrDefault("POSTGRES_USER", env.getOrDefault("POSTGRESQL_USER", "postgres"));
43+
this.username = env.getOrDefault("POSTGRES_USER", env.getOrDefault("POSTGRESQL_USERNAME", "postgres"));
4344
this.password = extractPassword(env);
44-
this.database = env.getOrDefault("POSTGRES_DB", env.getOrDefault("POSTGRESQL_DB", this.username));
45+
this.database = env.getOrDefault("POSTGRES_DB", env.getOrDefault("POSTGRESQL_DATABASE", this.username));
4546
}
4647

4748
private String extractPassword(Map<String, String> env) {

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* @author Phillip Webb
3333
* @author Scott Frederick
3434
* @author Sidmar Theodoro
35+
* @author He Zean
3536
*/
3637
class PostgresEnvironmentTests {
3738

@@ -48,7 +49,7 @@ void getUsernameWhenNoPostgresUser() {
4849
}
4950

5051
@Test
51-
void getUsernameWhenNoPostgresqlUser() {
52+
void getUsernameWhenNoPostgresqlUsername() {
5253
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRESQL_PASSWORD", "secret"));
5354
assertThat(environment.getUsername()).isEqualTo("postgres");
5455
}
@@ -61,9 +62,9 @@ void getUsernameWhenHasPostgresUser() {
6162
}
6263

6364
@Test
64-
void getUsernameWhenHasPostgresqlUser() {
65+
void getUsernameWhenHasPostgresqlUsername() {
6566
PostgresEnvironment environment = new PostgresEnvironment(
66-
Map.of("POSTGRESQL_USER", "me", "POSTGRESQL_PASSWORD", "secret"));
67+
Map.of("POSTGRESQL_USERNAME", "me", "POSTGRESQL_PASSWORD", "secret"));
6768
assertThat(environment.getUsername()).isEqualTo("me");
6869
}
6970

@@ -92,7 +93,7 @@ void getDatabaseWhenNoPostgresDbOrPostgresUser() {
9293
}
9394

9495
@Test
95-
void getDatabaseWhenNoPostgresqlDbOrPostgresUser() {
96+
void getDatabaseWhenNoPostgresqlDatabaseOrPostgresUsername() {
9697
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRESQL_PASSWORD", "secret"));
9798
assertThat(environment.getDatabase()).isEqualTo("postgres");
9899
}
@@ -105,9 +106,9 @@ void getDatabaseWhenNoPostgresDbAndPostgresUser() {
105106
}
106107

107108
@Test
108-
void getDatabaseWhenNoPostgresqlDbAndPostgresUser() {
109+
void getDatabaseWhenNoPostgresqlDatabaseAndPostgresqlUsername() {
109110
PostgresEnvironment environment = new PostgresEnvironment(
110-
Map.of("POSTGRESQL_USER", "me", "POSTGRESQL_PASSWORD", "secret"));
111+
Map.of("POSTGRESQL_USERNAME", "me", "POSTGRESQL_PASSWORD", "secret"));
111112
assertThat(environment.getDatabase()).isEqualTo("me");
112113
}
113114

@@ -119,9 +120,9 @@ void getDatabaseWhenHasPostgresDb() {
119120
}
120121

121122
@Test
122-
void getDatabaseWhenHasPostgresqlDb() {
123+
void getDatabaseWhenHasPostgresqlDatabase() {
123124
PostgresEnvironment environment = new PostgresEnvironment(
124-
Map.of("POSTGRESQL_DB", "db", "POSTGRESQL_PASSWORD", "secret"));
125+
Map.of("POSTGRESQL_DATABASE", "db", "POSTGRESQL_PASSWORD", "secret"));
125126
assertThat(environment.getDatabase()).isEqualTo("db");
126127
}
127128

0 commit comments

Comments
 (0)