Skip to content

Commit 5d82b16

Browse files
committed
test(postgresql): add coverage for custom credentials configuration
1 parent 2b53c47 commit 5d82b16

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

modules/postgresql/src/test/java/org/testcontainers/postgresql/PostgreSQLContainerTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ void testWithAdditionalUrlParamInJdbcUrl() {
122122
}
123123
}
124124

125+
@Test
126+
void testCustomCredentials() {
127+
try (
128+
129+
PostgreSQLContainer postgres = new PostgreSQLContainer(PostgreSQLTestImages.POSTGRES_TEST_IMAGE)
130+
.withDatabaseName("my_db")
131+
.withUsername("my_user")
132+
.withPassword("my_secret")
133+
) {
134+
postgres.start();
135+
136+
// Validações (Asserts)
137+
assertThat(postgres.getDatabaseName()).isEqualTo("my_db");
138+
assertThat(postgres.getUsername()).isEqualTo("my_user");
139+
assertThat(postgres.getPassword()).isEqualTo("my_secret");
140+
141+
// Valida se a URL de conexão reflete as mudanças
142+
String jdbcUrl = postgres.getJdbcUrl();
143+
assertThat(jdbcUrl).contains("/my_db");
144+
}
145+
}
146+
125147
private void assertHasCorrectExposedAndLivenessCheckPorts(PostgreSQLContainer postgres) {
126148
assertThat(postgres.getExposedPorts()).containsExactly(PostgreSQLContainer.POSTGRESQL_PORT);
127149
assertThat(postgres.getLivenessCheckPortNumbers())

0 commit comments

Comments
 (0)