|
42 | 42 | public class PostgresTest |
43 | 43 | { |
44 | 44 | private static final DockerImageName IMAGE_NAME = DockerImageName.parse("postgres:16"); |
| 45 | + private static final String SCHEMA_NAME = "test"; |
45 | 46 |
|
46 | 47 | private PostgreSQLContainer<?> postgres; |
47 | 48 |
|
48 | 49 | @Before |
49 | 50 | public void beforeTest() { |
50 | | - postgres = new PostgreSQLContainer<>(IMAGE_NAME); |
| 51 | + postgres = new PostgreSQLContainer<>(IMAGE_NAME).withInitScript("postgres_init_script.sql"); |
51 | 52 | postgres.start(); |
52 | 53 | } |
53 | 54 |
|
@@ -139,6 +140,31 @@ public void testCredentialRotation() |
139 | 140 | exerciseConfig(config, 3); |
140 | 141 | } |
141 | 142 |
|
| 143 | + @Test |
| 144 | + public void testSchema() throws Exception { |
| 145 | + HikariConfig config = createConfig(postgres); |
| 146 | + config.setMinimumIdle(1); |
| 147 | + config.setMaximumPoolSize(1); |
| 148 | + config.setSchema(SCHEMA_NAME); |
| 149 | + |
| 150 | + try (HikariDataSource ds = new HikariDataSource(config)) { |
| 151 | + assertTrue(ds.isRunning()); |
| 152 | + try (Connection connection = ds.getConnection()) { |
| 153 | + // The connection should be using the schema specified in the config |
| 154 | + assertEquals(SCHEMA_NAME, connection.getSchema()); |
| 155 | + // Explicitly set the schema to an invalid schema |
| 156 | + connection.setSchema("invalid"); |
| 157 | + // The connection should have a null schema after setting to an invalid schema |
| 158 | + assertNull(connection.getSchema()); |
| 159 | + } |
| 160 | + try (Connection connection = ds.getConnection()) { |
| 161 | + // The connection should be reset to the schema specified in the config |
| 162 | + assertEquals(SCHEMA_NAME, connection.getSchema()); |
| 163 | + } |
| 164 | + assertTrue(ds.isRunning()); |
| 165 | + } |
| 166 | + } |
| 167 | + |
142 | 168 | static private void exerciseConfig(HikariConfig config, int numThreads) { |
143 | 169 | try (final HikariDataSource ds = new HikariDataSource(config)) { |
144 | 170 | assertTrue(ds.isRunning()); |
|
0 commit comments