Skip to content

Commit 7e37202

Browse files
stevenschlanskertomix26
authored andcommitted
PreparedDbProvider: include username in connection string
1 parent f9668ae commit 7e37202

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/java/io/zonky/test/db/postgres/embedded/PreparedDbProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
public class PreparedDbProvider
4141
{
42-
private static final String JDBC_FORMAT = "jdbc:postgresql://localhost:%d/%s";
42+
private static final String JDBC_FORMAT = "jdbc:postgresql://localhost:%d/%s?user=%s";
4343

4444
/**
4545
* Each database cluster's <code>template1</code> database has a unique set of schema
@@ -145,7 +145,7 @@ public DataSource createDataSource() throws SQLException
145145

146146
String getJdbcUri(DbInfo db)
147147
{
148-
return String.format(JDBC_FORMAT, db.port, db.dbName);
148+
return String.format(JDBC_FORMAT, db.port, db.dbName, db.user);
149149
}
150150

151151
/**

src/test/java/io/zonky/test/db/postgres/embedded/PreparedDbTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static org.junit.Assert.assertEquals;
1717

1818
import java.sql.Connection;
19+
import java.sql.DriverManager;
1920
import java.sql.PreparedStatement;
2021
import java.sql.ResultSet;
2122
import java.sql.SQLException;
@@ -72,6 +73,15 @@ public void testEquivalentAccess() throws SQLException {
7273
DataSource dataSource = dbA1.getTestDatabase();
7374
try (Connection c = dataSource.getConnection(); Statement stmt = c.createStatement()) {
7475
commonAssertion(stmt);
76+
assertEquals(dbInfo.getUser(), c.getMetaData().getUserName());
77+
}
78+
}
79+
80+
@Test
81+
public void testDbUri() throws Exception {
82+
try (Connection c = DriverManager.getConnection(dbA1.getDbProvider().createDatabase());
83+
Statement stmt = c.createStatement()) {
84+
commonAssertion(stmt);
7585
}
7686
}
7787

0 commit comments

Comments
 (0)