-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from MTES-MCT/backend-tests
Try running backend tests on CI
- Loading branch information
Showing
5 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
backend/src/test/kotlin/fr/gouv/gmampa/rapportnav/infrastructure/database/AbstractDBTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package fr.gouv.gmampa.rapportnav.infrastructure.database | ||
|
||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.DynamicPropertyRegistry | ||
import org.springframework.test.context.DynamicPropertySource | ||
import org.springframework.test.context.TestPropertySource | ||
import org.testcontainers.containers.PostgreSQLContainer | ||
import org.testcontainers.containers.output.OutputFrame | ||
import org.testcontainers.containers.output.ToStringConsumer | ||
import org.testcontainers.containers.wait.strategy.Wait | ||
import org.testcontainers.junit.jupiter.Testcontainers | ||
import java.time.Duration | ||
import java.time.temporal.ChronoUnit | ||
|
||
@Testcontainers | ||
@TestPropertySource("classpath:/application.properties") | ||
@SpringBootTest | ||
abstract class AbstractDBTests { | ||
|
||
companion object { | ||
@JvmStatic | ||
val container = PostgreSQLContainer("postgres:15-bookworm") | ||
.apply { | ||
withExposedPorts(5432) | ||
withEnv("POSTGRES_DB", "testdb") | ||
withEnv("POSTGRES_USER", "postgres") | ||
withEnv("POSTGRES_PASSWORD", "postgres") | ||
waitingFor( | ||
Wait.forLogMessage(".*ready to accept connections.*\\s", 2), | ||
) | ||
withStartupTimeout(Duration.of(60L, ChronoUnit.SECONDS)) | ||
this.start() | ||
} | ||
|
||
@JvmStatic | ||
@DynamicPropertySource | ||
fun properties(registry: DynamicPropertyRegistry) { | ||
registry.add("spring.datasource.url") { getJdbcUrl() } | ||
} | ||
|
||
private fun getJdbcUrl(): String { | ||
val toStringConsumer = ToStringConsumer() | ||
container.followOutput(toStringConsumer, OutputFrame.OutputType.STDOUT) | ||
|
||
return "jdbc:postgresql://" + container.containerIpAddress + ":" + container.getMappedPort( | ||
PostgreSQLContainer.POSTGRESQL_PORT, | ||
).toString() + "/testdb?user=postgres&password=postgres" | ||
} | ||
} | ||
} |