-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e55ab3
commit 64ed529
Showing
7 changed files
with
133 additions
and
1 deletion.
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
65 changes: 65 additions & 0 deletions
65
backend/src/test/kotlin/app/ehrenamtskarte/backend/IntegrationTest.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,65 @@ | ||
package app.ehrenamtskarte.backend | ||
|
||
import app.ehrenamtskarte.backend.common.database.Database | ||
import app.ehrenamtskarte.backend.config.BackendConfiguration | ||
import app.ehrenamtskarte.backend.config.PostgresConfig | ||
import app.ehrenamtskarte.backend.migration.MigrationUtils | ||
import app.ehrenamtskarte.backend.projects.database.ProjectEntity | ||
import app.ehrenamtskarte.backend.regions.database.RegionEntity | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import org.junit.AfterClass | ||
import org.junit.BeforeClass | ||
import org.junit.Test | ||
import org.testcontainers.containers.PostgreSQLContainer | ||
import org.testcontainers.utility.DockerImageName | ||
import kotlin.test.assertEquals | ||
|
||
open class IntegrationTest { | ||
companion object { | ||
private var postgisImage = DockerImageName.parse("postgis/postgis:13-3.0-alpine") | ||
private var postgisContainer = PostgreSQLContainer(postgisImage.asCompatibleSubstituteFor("postgres")) | ||
|
||
@JvmStatic | ||
@BeforeClass | ||
fun setupDatabase() { | ||
val resource = ClassLoader.getSystemResource("config.test.yml") | ||
?: throw Exception("Configuration file 'config.test.yml' not found") | ||
|
||
postgisContainer.start() | ||
|
||
val config = BackendConfiguration.load(resource) | ||
.copy(postgres = PostgresConfig(postgisContainer.jdbcUrl, postgisContainer.username, postgisContainer.password)) | ||
|
||
val database = Database.setupWithoutMigrationCheck(config) | ||
MigrationUtils.applyRequiredMigrations(database) | ||
Database.setupInitialData(config) | ||
} | ||
|
||
@JvmStatic | ||
@AfterClass | ||
fun tearDownDatabase() { | ||
postgisContainer.stop() | ||
} | ||
} | ||
|
||
/** | ||
* Temporary tests to verify that the database is properly configured | ||
*/ | ||
@Test | ||
fun verifyProjectCount() { | ||
var projectCount = 0L | ||
transaction { | ||
projectCount = ProjectEntity.count() | ||
} | ||
assertEquals(2L, projectCount) | ||
} | ||
|
||
@Test | ||
fun verifyRegionCount() { | ||
var regionCount = 0L | ||
transaction { | ||
regionCount = RegionEntity.count() | ||
} | ||
assertEquals(94L, regionCount) | ||
} | ||
} |
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,39 @@ | ||
production: false | ||
postgres: | ||
url: dummy | ||
user: test | ||
password: test | ||
map: | ||
baseUrl: dummy | ||
geocoding: | ||
enabled: false | ||
host: dummy | ||
csvWriter: | ||
enabled: false | ||
server: | ||
host: 0.0.0.0 | ||
port: 8000 | ||
dataDirectory: ./data | ||
projects: | ||
- id: bayern.ehrenamtskarte.app | ||
importUrl: dummy | ||
pipelineName: dummy | ||
administrationBaseUrl: dummy | ||
administrationName: dummy | ||
timezone: "Europe/Berlin" | ||
smtp: | ||
host: dummy | ||
port: 587 | ||
username: OVERRIDE_IN_LOCAL_CONFIG | ||
password: OVERRIDE_IN_LOCAL_CONFIG | ||
- id: nuernberg.sozialpass.app | ||
importUrl: dummy | ||
pipelineName: dummy | ||
administrationBaseUrl: dummy | ||
administrationName: dummy | ||
timezone: "Europe/Berlin" | ||
smtp: | ||
host: dummy | ||
port: 587 | ||
username: OVERRIDE_IN_LOCAL_CONFIG | ||
password: OVERRIDE_IN_LOCAL_CONFIG |
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,14 @@ | ||
# Testcontainers troubleshooting | ||
|
||
Testcontainers is the framework we use for integration tests in the backend. | ||
It allows to manage application dependencies (such as database, etc) in Docker containers in test code. | ||
|
||
Running tests based on Testcontainers requires a valid Docker environment. | ||
|
||
If you get the following error, make sure your current user has permission to execute `/var/run/docker.sock` and `/var/run/docker.pid` | ||
|
||
2024-07-15T19:27:48.460+0000 [DEBUG] [TestEventLogger] [Test worker] INFO org.testcontainers.dockerclient.DockerMachineClientProviderStrategy - docker-machine executable was not found on PATH ([/home/circleci/.local/bin, /home/circleci/.npm-global/bin, /opt/sbt/bin, /opt/gradle/bin, /opt/apache-maven/bin, /home/circleci/bin, /home/circleci/.local/bin, /usr/local/sbin, /usr/local/bin, /usr/sbin, /usr/bin, /sbin, /bin]) | ||
2024-07-15T19:27:48.460+0000 [DEBUG] [TestEventLogger] [Test worker] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were: | ||
2024-07-15T19:27:48.460+0000 [DEBUG] [TestEventLogger] UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock) | ||
2024-07-15T19:27:48.460+0000 [DEBUG] [TestEventLogger] DockerDesktopClientProviderStrategy: failed with exception NullPointerException (Cannot invoke "java.nio.file.Path.toString()" because the return value of "org.testcontainers.dockerclient.DockerDesktopClientProviderStrategy.getSocketPath()" is null)As no valid configuration was found, execution cannot continue. | ||
2024-07-15T19:27:48.460+0000 [DEBUG] [TestEventLogger] See https://java.testcontainers.org/on_failure.html for more details. |