diff --git a/config-repo/pcp-request-service.yaml b/config-repo/pcp-request-service.yaml index ef094a1..6f2e83e 100644 --- a/config-repo/pcp-request-service.yaml +++ b/config-repo/pcp-request-service.yaml @@ -67,3 +67,14 @@ app: cleanup-cron: "0 0 3 * * *" grid: enabled: true + +--- +spring: + config: + activate: + on-profile: local + datasource: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://${pcp.infra.postgres.host}:${pcp.infra.postgres.port}/pcp_requests + username: postgres + password: password diff --git a/services/pcp-request-service/src/test/kotlin/org/nstart/dep265/requestservice/RequestServiceConfigTest.kt b/services/pcp-request-service/src/test/kotlin/org/nstart/dep265/requestservice/RequestServiceConfigTest.kt new file mode 100644 index 0000000..cb0f87a --- /dev/null +++ b/services/pcp-request-service/src/test/kotlin/org/nstart/dep265/requestservice/RequestServiceConfigTest.kt @@ -0,0 +1,36 @@ +package org.nstart.dep265.requestservice + +import java.nio.file.Files +import java.nio.file.Path +import kotlin.io.path.readText +import kotlin.test.Test +import kotlin.test.assertTrue + +class RequestServiceConfigTest { + @Test + fun `local profile uses concrete postgres datasource`() { + val config = configRepositoryFile().readText() + + assertTrue(config.contains("on-profile: local")) + assertTrue(config.contains("url: jdbc:postgresql://\${pcp.infra.postgres.host}:\${pcp.infra.postgres.port}/pcp_requests")) + assertTrue(config.contains("username: postgres")) + assertTrue(config.contains("password: password")) + } + + @Test + fun `shared datasource keeps environment placeholders for deployed profiles`() { + val config = configRepositoryFile().readText() + + assertTrue(config.contains("url: \"\${SPRING_DATASOURCE_URL}\"")) + assertTrue(config.contains("username: \"\${SPRING_DATASOURCE_USERNAME}\"")) + assertTrue(config.contains("password: \"\${SPRING_DATASOURCE_PASSWORD}\"")) + } + + private fun configRepositoryFile(): Path { + val rootPath = Path.of("config-repo/pcp-request-service.yaml") + if (Files.exists(rootPath)) { + return rootPath + } + return Path.of("../../config-repo/pcp-request-service.yaml") + } +}