Skip to content

Commit 2681006

Browse files
author
raju.gupta
committed
Refactor performSelectMaxConnectionsQuery and performSelectVersionQuery to accept expected values for assertions
1 parent e94be98 commit 2681006

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

modules/jdbc-test/src/main/java/org/testcontainers/db/AbstractContainerDatabaseTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ protected void performSelectFooBarQuery(final JdbcDatabaseContainer<?> container
6565
);
6666
}
6767

68-
protected void performSelectMaxConnectionsQuery(final JdbcDatabaseContainer<?> container) throws SQLException {
68+
protected void performSelectMaxConnectionsQuery(
69+
final JdbcDatabaseContainer<?> container,
70+
final String expectedMaxConnections
71+
) throws SQLException {
6972
performQuery(
7073
container,
7174
"SELECT current_setting('max_connections')",
@@ -74,13 +77,17 @@ protected void performSelectMaxConnectionsQuery(final JdbcDatabaseContainer<?> c
7477
.assertThatNoException()
7578
.isThrownBy(() -> {
7679
String result = resultSet.getString(1);
77-
Assertions.assertThat(result).as("max_connections should be overridden").isEqualTo("42");
80+
Assertions
81+
.assertThat(result)
82+
.as("max_connections should be overridden")
83+
.isEqualTo(expectedMaxConnections);
7884
});
7985
}
8086
);
8187
}
8288

83-
protected void performSelectVersionQuery(final JdbcDatabaseContainer<?> container) throws SQLException {
89+
protected void performSelectVersionQuery(final JdbcDatabaseContainer<?> container, final String expectedVersion)
90+
throws SQLException {
8491
performQuery(
8592
container,
8693
"SELECT VERSION()",
@@ -92,7 +99,7 @@ protected void performSelectVersionQuery(final JdbcDatabaseContainer<?> containe
9299
Assertions
93100
.assertThat(resultSetString)
94101
.as("The database version can be set using a container rule parameter")
95-
.startsWith("10.3.39");
102+
.startsWith(expectedVersion);
96103
});
97104
}
98105
);

modules/mysql/src/test/java/org/testcontainers/mysql/MultiVersionMySQLTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static DockerImageName[] params() {
2424
void versionCheckTest(DockerImageName dockerImageName) throws SQLException {
2525
try (MySQLContainer mysql = new MySQLContainer(dockerImageName)) {
2626
mysql.start();
27-
performSelectVersionQuery(mysql);
27+
performSelectVersionQuery(mysql, dockerImageName.getVersionPart());
2828
}
2929
}
3030
}

modules/mysql/src/test/java/org/testcontainers/mysql/MySQLContainerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void testSpecificVersion() throws SQLException {
5757
) {
5858
mysqlOldVersion.start();
5959

60-
performSelectVersionQuery(mysqlOldVersion);
60+
performSelectVersionQuery(mysqlOldVersion, "8.0.36");
6161
}
6262
}
6363

modules/postgresql/src/test/java/org/testcontainers/containers/TimescaleDBContainerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void testCommandOverride() throws SQLException {
2525
) {
2626
postgres.start();
2727

28-
performSelectMaxConnectionsQuery((JdbcDatabaseContainer<?>) postgres);
28+
performSelectMaxConnectionsQuery((JdbcDatabaseContainer<?>) postgres, "42");
2929
}
3030
}
3131

@@ -39,7 +39,7 @@ void testUnsetCommand() throws SQLException {
3939
) {
4040
postgres.start();
4141

42-
performSelectMaxConnectionsQuery((JdbcDatabaseContainer<?>) postgres);
42+
performSelectMaxConnectionsQuery((JdbcDatabaseContainer<?>) postgres, "100");
4343
}
4444
}
4545

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void testCommandOverride() throws SQLException {
4040
) {
4141
postgres.start();
4242

43-
performSelectMaxConnectionsQuery(postgres);
43+
performSelectMaxConnectionsQuery(postgres, "42");
4444
}
4545
}
4646

@@ -53,7 +53,9 @@ void testUnsetCommand() throws SQLException {
5353
) {
5454
postgres.start();
5555

56-
performSelectMaxConnectionsQuery(postgres);
56+
// After unsetting the command, max_connections should be the default value (100), not 42
57+
58+
performSelectMaxConnectionsQuery(postgres, "100");
5759
}
5860
}
5961

0 commit comments

Comments
 (0)