Skip to content

Commit 92b44bc

Browse files
committed
Refactor tests
1 parent b4de03c commit 92b44bc

File tree

5 files changed

+41
-49
lines changed

5 files changed

+41
-49
lines changed

docker/docker-compose-base.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ services:
8686

8787
postgres:
8888
container_name: postgres
89-
image: postgres:16.4
89+
image: postgres:17.0
9090
shm_size: "2gb"
9191
environment:
9292
POSTGRES_DB: "otel_demo_db"

spring-boot-2-demo-app/src/test/java/io/github/mfvanek/spring/boot2/test/IndexesMaintenanceTest.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnHost;
44
import io.github.mfvanek.pg.common.maintenance.Diagnostic;
55
import io.github.mfvanek.pg.model.DbObject;
6+
import io.github.mfvanek.pg.model.PgContext;
67
import io.github.mfvanek.pg.model.column.Column;
7-
import io.github.mfvanek.pg.model.table.Table;
88
import io.github.mfvanek.spring.boot2.test.support.TestBase;
9+
import org.assertj.core.api.ListAssert;
910
import org.junit.jupiter.api.DisplayName;
1011
import org.junit.jupiter.api.Test;
1112
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,35 +26,29 @@ class IndexesMaintenanceTest extends TestBase {
2526
void checkPostgresVersion() {
2627
final String pgVersion = jdbcTemplate.queryForObject("select version();", String.class);
2728
assertThat(pgVersion)
28-
.startsWith("PostgreSQL 16.4");
29+
.startsWith("PostgreSQL 17.0");
2930
}
3031

3132
@Test
3233
void databaseStructureCheckForPublicSchema() {
3334
assertThat(checks)
34-
.hasSameSizeAs(Diagnostic.values());
35+
.hasSameSizeAs(Diagnostic.values());
3536

3637
checks.stream()
37-
.filter(DatabaseCheckOnHost::isStatic)
38-
.forEach(check -> {
39-
switch (check.getDiagnostic()) {
40-
case TABLES_WITHOUT_PRIMARY_KEY, TABLES_WITHOUT_DESCRIPTION -> assertThat(check.check())
41-
.asInstanceOf(list(Table.class))
42-
.hasSize(1)
43-
.containsExactly(Table.of("databasechangelog", 0L));
44-
45-
case COLUMNS_WITHOUT_DESCRIPTION -> assertThat(check.check())
46-
.asInstanceOf(list(Column.class))
47-
.hasSize(14)
48-
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));
49-
50-
case TABLES_WITH_MISSING_INDEXES -> assertThat(check.check())
51-
.hasSizeLessThanOrEqualTo(1); // TODO skip runtime checks after https://github.com/mfvanek/pg-index-health/issues/456
52-
53-
default -> assertThat(check.check())
54-
.as(check.getDiagnostic().name())
55-
.isEmpty();
56-
}
57-
});
38+
.filter(DatabaseCheckOnHost::isStatic)
39+
.forEach(check -> {
40+
final List<? extends DbObject> objects = check.check(PgContext.ofPublic(), o -> !o.getName().equalsIgnoreCase("databasechangelog"));
41+
final ListAssert<? extends DbObject> checkAssert = assertThat(objects)
42+
.as(check.getDiagnostic().name());
43+
44+
if (check.getDiagnostic() == Diagnostic.COLUMNS_WITHOUT_DESCRIPTION) {
45+
assertThat(objects)
46+
.asInstanceOf(list(Column.class))
47+
.hasSize(14)
48+
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));
49+
} else {
50+
checkAssert.isEmpty();
51+
}
52+
});
5853
}
5954
}

spring-boot-2-demo-app/src/test/java/io/github/mfvanek/spring/boot2/test/support/PostgresInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class PostgresInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
1212

13-
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:16.4");
13+
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:17.0");
1414
private static final Network NETWORK = Network.newNetwork();
1515
private static final PostgreSQLContainer<?> CONTAINER = new PostgreSQLContainer<>(IMAGE);
1616

spring-boot-3-demo-app/src/test/java/io/github/mfvanek/spring/boot3/test/IndexesMaintenanceTest.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnHost;
44
import io.github.mfvanek.pg.common.maintenance.Diagnostic;
55
import io.github.mfvanek.pg.model.DbObject;
6+
import io.github.mfvanek.pg.model.PgContext;
67
import io.github.mfvanek.pg.model.column.Column;
7-
import io.github.mfvanek.pg.model.table.Table;
88
import io.github.mfvanek.spring.boot3.test.support.TestBase;
9+
import org.assertj.core.api.ListAssert;
910
import org.junit.jupiter.api.DisplayName;
1011
import org.junit.jupiter.api.Test;
1112
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,33 +26,29 @@ class IndexesMaintenanceTest extends TestBase {
2526
void checkPostgresVersion() {
2627
final String pgVersion = jdbcTemplate.queryForObject("select version();", String.class);
2728
assertThat(pgVersion)
28-
.startsWith("PostgreSQL 16.4");
29+
.startsWith("PostgreSQL 17.0");
2930
}
3031

3132
@Test
3233
void databaseStructureCheckForPublicSchema() {
3334
assertThat(checks)
3435
.hasSameSizeAs(Diagnostic.values());
3536

36-
checks.forEach(check -> {
37-
switch (check.getDiagnostic()) {
38-
case TABLES_WITHOUT_PRIMARY_KEY, TABLES_WITHOUT_DESCRIPTION -> assertThat(check.check())
39-
.asInstanceOf(list(Table.class))
40-
.hasSize(1)
41-
.containsExactly(Table.of("databasechangelog", 0L));
42-
43-
case COLUMNS_WITHOUT_DESCRIPTION -> assertThat(check.check())
44-
.asInstanceOf(list(Column.class))
45-
.hasSize(14)
46-
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));
47-
48-
case TABLES_WITH_MISSING_INDEXES -> assertThat(check.check())
49-
.hasSizeLessThanOrEqualTo(1); // TODO skip runtime checks after https://github.com/mfvanek/pg-index-health/issues/456
50-
51-
default -> assertThat(check.check())
52-
.as(check.getDiagnostic().name())
53-
.isEmpty();
54-
}
55-
});
37+
checks.stream()
38+
.filter(DatabaseCheckOnHost::isStatic)
39+
.forEach(check -> {
40+
final List<? extends DbObject> objects = check.check(PgContext.ofPublic(), o -> !o.getName().equalsIgnoreCase("databasechangelog"));
41+
final ListAssert<? extends DbObject> checkAssert = assertThat(objects)
42+
.as(check.getDiagnostic().name());
43+
44+
if (check.getDiagnostic() == Diagnostic.COLUMNS_WITHOUT_DESCRIPTION) {
45+
assertThat(objects)
46+
.asInstanceOf(list(Column.class))
47+
.hasSize(14)
48+
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));
49+
} else {
50+
checkAssert.isEmpty();
51+
}
52+
});
5653
}
5754
}

spring-boot-3-demo-app/src/test/java/io/github/mfvanek/spring/boot3/test/support/PostgresInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class PostgresInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
1212

13-
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:16.4");
13+
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:17.0");
1414
private static final Network NETWORK = Network.newNetwork();
1515
private static final PostgreSQLContainer<?> CONTAINER = new PostgreSQLContainer<>(IMAGE);
1616

0 commit comments

Comments
 (0)