Compare commits
3
Commits
v0.2
...
124293da05
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
124293da05
|
||
|
|
e262f35b27
|
||
|
|
77e4cab8ad
|
@@ -0,0 +1,7 @@
|
||||
* text=auto
|
||||
* eol=lf
|
||||
*.sh text eol=lf
|
||||
*.png binary
|
||||
*.jar binary
|
||||
gradlew.bat eol=crlf
|
||||
gradlew text eol=lf
|
||||
+22
-18
@@ -80,36 +80,40 @@ jobs:
|
||||
continue-on-error: false
|
||||
|
||||
test:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GRADLE_CACHE_DIR: ${{ github.workspace }}/.gradle-docker-cache
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
- name: Prepare docker secrets
|
||||
run: |
|
||||
[ -f docker/postgresql.secret ] || echo -n "changeit" > docker/postgresql.secret
|
||||
|
||||
- name: Restore Gradle cache
|
||||
- name: Generate cache key
|
||||
id: cache-key-generator
|
||||
run: echo "key=gradle-docker-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Restore Gradle cache (Docker)
|
||||
uses: actions/cache@v6
|
||||
with:
|
||||
path: |
|
||||
~/.gradle/caches
|
||||
~/.gradle/wrapper
|
||||
key: ${{ needs.build.outputs.cache-key }}
|
||||
path: ${{ env.GRADLE_CACHE_DIR }}
|
||||
key: ${{ steps.cache-key-generator.outputs.key }}
|
||||
restore-keys: |
|
||||
gradle-${{ runner.os }}-
|
||||
gradle-docker-${{ runner.os }}-
|
||||
|
||||
- name: Grant execute permission to Gradle wrapper
|
||||
run: chmod +x gradlew
|
||||
- name: Prepare cache directory permissions
|
||||
run: |
|
||||
mkdir -p "$GRADLE_CACHE_DIR"
|
||||
chmod -R 777 "$GRADLE_CACHE_DIR"
|
||||
|
||||
- name: Start CI Docker Compose services
|
||||
run: ./gradlew ciComposeUp -Pci
|
||||
- name: Run tests in Docker
|
||||
run: docker compose -f docker/docker-compose-test.yaml run --rm tests
|
||||
|
||||
- name: Run tests
|
||||
run: ./gradlew test -x ciComposeUp -Pci --no-daemon
|
||||
- name: Shut down Docker services
|
||||
if: always()
|
||||
run: docker compose -f docker/docker-compose-test.yaml down -v
|
||||
|
||||
- name: Upload test reports
|
||||
if: always()
|
||||
|
||||
@@ -37,3 +37,4 @@ out/
|
||||
/docker/.env
|
||||
/docker/*.secret
|
||||
*.hprof
|
||||
/.gradle-docker-cache/
|
||||
|
||||
+11
-40
@@ -1,4 +1,3 @@
|
||||
import com.avast.gradle.dockercompose.ComposeExtension
|
||||
import org.jlleitschuh.gradle.ktlint.KtlintExtension
|
||||
|
||||
val ktorVersion: Provider<String> = providers.gradleProperty("ktor_version")
|
||||
@@ -15,7 +14,6 @@ plugins {
|
||||
id("io.ktor.plugin") version "3.5.1"
|
||||
id("org.jetbrains.kotlin.plugin.serialization") version "2.4.10"
|
||||
id("org.jlleitschuh.gradle.ktlint") version "14.2.0"
|
||||
id("com.avast.gradle.docker-compose") version "0.17.12"
|
||||
}
|
||||
|
||||
group = "io.github.flecomte"
|
||||
@@ -48,44 +46,17 @@ java {
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
configure<ComposeExtension> {
|
||||
createNested("test").apply {
|
||||
useComposeFiles.set(listOf("docker/docker-compose-test.yaml"))
|
||||
setProjectName("event-demo-test")
|
||||
jvmArgs("-Djdk.attach.allowAttachSelf=true", "-XX:+EnableDynamicAgentLoading")
|
||||
// Dynamic self-attach (used by MockK/ByteBuddy) times out in Docker containers because the
|
||||
// SIGQUIT-triggered AttachListener handshake never completes there. Loading the byte-buddy
|
||||
// agent jar statically via -javaagent avoids the attach handshake entirely: MockK detects the
|
||||
// pre-installed Instrumentation instance and skips dynamic attach.
|
||||
doFirst {
|
||||
val agentJar =
|
||||
classpath.files.firstOrNull { it.name.startsWith("byte-buddy-agent") }
|
||||
?: error("byte-buddy-agent jar not found on test classpath")
|
||||
jvmArgs("-javaagent:$agentJar")
|
||||
}
|
||||
createNested("dev").apply {
|
||||
useComposeFiles.set(listOf("docker/docker-compose-dev.yaml"))
|
||||
setProjectName("event-demo-dev")
|
||||
}
|
||||
createNested("ci").apply {
|
||||
useComposeFiles.set(listOf("docker/docker-compose-ci.yaml"))
|
||||
setProjectName("event-demo-ci")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
if (project.hasProperty("ci")) {
|
||||
dependsOn("ciComposeUp")
|
||||
} else {
|
||||
dependsOn("testComposeUp")
|
||||
}
|
||||
}
|
||||
tasks.named("run") {
|
||||
dependsOn("devComposeUp")
|
||||
}
|
||||
tasks.composeUp {
|
||||
dependsOn("copyEnv")
|
||||
}
|
||||
tasks.named("devComposeUp") {
|
||||
dependsOn("copyEnv")
|
||||
}
|
||||
tasks.named("testComposeUp") {
|
||||
dependsOn("copyEnv")
|
||||
}
|
||||
tasks.named("ciComposeUp") {
|
||||
dependsOn("copyEnv")
|
||||
}
|
||||
|
||||
tasks.register<Copy>("copyEnv") {
|
||||
@@ -154,6 +125,6 @@ dependencies {
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:${kotlinVersion.get()}")
|
||||
testImplementation("io.ktor:ktor-server-test-host-jvm:${ktorVersion.get()}")
|
||||
testImplementation("io.kotest:kotest-runner-junit5:${kotestVersion.get()}")
|
||||
testImplementation("io.mockk:mockk:1.13.17")
|
||||
testImplementation("io.mockk:mockk:1.14.11")
|
||||
testImplementation("com.tngtech.archunit:archunit-junit5:1.3.0")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Image officielle Gradle avec JDK 21 déjà installé
|
||||
FROM gradle:9.6.1-jdk21
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copie du wrapper et des fichiers de config en premier pour profiter du cache Docker
|
||||
COPY build.gradle.kts settings.gradle.kts ./
|
||||
|
||||
# Lance les tests Kotlin
|
||||
CMD ["gradle", "test", "--no-daemon"]
|
||||
@@ -1,4 +1,8 @@
|
||||
name: event-demo-test
|
||||
include:
|
||||
- path:
|
||||
- docker-compose-test.yaml
|
||||
- parts/docker-compose-databases.yaml
|
||||
- parts/docker-compose-databases-expose.yaml
|
||||
- parts/docker-compose-tools.yaml
|
||||
- parts/docker-compose-tools-local.yaml
|
||||
- parts/docker-compose-traefik.yaml
|
||||
@@ -2,6 +2,5 @@ name: event-demo-test
|
||||
include:
|
||||
- path:
|
||||
- parts/docker-compose-databases.yaml
|
||||
- parts/docker-compose-databases-expose.yaml
|
||||
- parts/docker-compose-tools.yaml
|
||||
- parts/docker-compose-test.yaml
|
||||
- parts/docker-compose-traefik.yaml
|
||||
@@ -0,0 +1,20 @@
|
||||
services:
|
||||
tests:
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: docker/DockerfileTest
|
||||
volumes:
|
||||
- ${GRADLE_CACHE_DIR:-gradle-cache}:/home/gradle/.gradle
|
||||
- ../..:/app
|
||||
depends_on:
|
||||
flyway:
|
||||
condition: service_completed_successfully
|
||||
postgresql:
|
||||
condition: service_healthy
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
|
||||
volumes:
|
||||
gradle-cache:
|
||||
@@ -0,0 +1,18 @@
|
||||
services:
|
||||
pgadmin:
|
||||
environment:
|
||||
PGADMIN_CONFIG_SERVER_MODE: 'False'
|
||||
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'
|
||||
configs:
|
||||
- source: pgpass
|
||||
target: /pgpass
|
||||
mode: 0600
|
||||
uid: "5050"
|
||||
gid: "5050"
|
||||
- source: servers_json
|
||||
target: /pgadmin4/servers.json
|
||||
|
||||
configs:
|
||||
pgpass:
|
||||
content: |
|
||||
*:*:*:event-demo:changeit
|
||||
@@ -4,18 +4,11 @@ services:
|
||||
environment:
|
||||
PGADMIN_DEFAULT_EMAIL: $PGADMIN_DEFAULT_EMAIL
|
||||
PGADMIN_DEFAULT_PASSWORD_FILE: /run/secrets/pgadmin_password
|
||||
PGADMIN_CONFIG_SERVER_MODE: 'False'
|
||||
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'
|
||||
secrets:
|
||||
- pgadmin_password
|
||||
volumes:
|
||||
- pgadmin_data:/var/lib/pgadmin
|
||||
configs:
|
||||
- source: pgpass
|
||||
target: /pgpass
|
||||
mode: 0600
|
||||
uid: "5050"
|
||||
gid: "5050"
|
||||
- source: servers_json
|
||||
target: /pgadmin4/servers.json
|
||||
labels:
|
||||
@@ -35,9 +28,6 @@ services:
|
||||
- "traefik.http.services.rabbitmq-management.loadbalancer.server.port=15672"
|
||||
|
||||
configs:
|
||||
pgpass:
|
||||
content: |
|
||||
*:*:*:event-demo:changeit
|
||||
servers_json:
|
||||
content: |
|
||||
{
|
||||
|
||||
@@ -13,12 +13,12 @@ jwt {
|
||||
}
|
||||
|
||||
redis {
|
||||
url = "redis://localhost:6379"
|
||||
url = "redis://redis:6379"
|
||||
url = ${?REDIS_URL}
|
||||
}
|
||||
|
||||
postgresql {
|
||||
url = "jdbc:postgresql://localhost:5432/event-demo"
|
||||
url = "jdbc:postgresql://postgresql/event-demo"
|
||||
url = ${?POSTGRESQL_URL}
|
||||
|
||||
username = "event-demo"
|
||||
@@ -29,7 +29,7 @@ postgresql {
|
||||
}
|
||||
|
||||
rabbitmq {
|
||||
url = "localhost"
|
||||
url = "rabbitmq"
|
||||
url = ${?RABBITMQ_URL}
|
||||
|
||||
port = "5672"
|
||||
|
||||
@@ -2,6 +2,7 @@ package eventDemo.libs.bus
|
||||
|
||||
import com.rabbitmq.client.ConnectionFactory
|
||||
import eventDemo.testHelpers.spyPing
|
||||
import eventDemo.testHelpers.testKoinApplicationWithConfig
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.datatest.withData
|
||||
import io.kotest.matchers.string.shouldStartWith
|
||||
@@ -15,19 +16,13 @@ private data class ObjTest(
|
||||
class BusTest :
|
||||
FunSpec({
|
||||
context("Pub/sub") {
|
||||
val factory =
|
||||
ConnectionFactory().apply {
|
||||
host = "localhost"
|
||||
port = 5672
|
||||
username = "event-demo"
|
||||
password = "changeit"
|
||||
}
|
||||
testKoinApplicationWithConfig {
|
||||
val list: Map<String, Bus<ObjTest>> =
|
||||
mapOf(
|
||||
BusInMemory::class.java.simpleName to BusInMemory(),
|
||||
BusInRabbitMQ::class.java.simpleName to
|
||||
BusInRabbitMQ(
|
||||
factory,
|
||||
get<ConnectionFactory>(),
|
||||
"testExchange",
|
||||
{ it.value },
|
||||
{ ObjTest(it) },
|
||||
@@ -45,4 +40,5 @@ class BusTest :
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -15,10 +15,13 @@ import org.koin.core.module.KoinApplicationDslMarker
|
||||
import org.koin.dsl.koinApplication
|
||||
import org.koin.ktor.ext.getKoin
|
||||
|
||||
const val CONFIG_FILE_NAME = "application.conf"
|
||||
|
||||
@KoinApplicationDslMarker
|
||||
suspend fun <T> testKoinApplicationWithConfig(block: suspend Koin.() -> T): T =
|
||||
koinApplication { modules(appKoinModule(ApplicationConfig("application.conf").configuration)) }
|
||||
.koin
|
||||
koinApplication {
|
||||
modules(appKoinModule(ApplicationConfig(CONFIG_FILE_NAME).configuration))
|
||||
}.koin
|
||||
.run {
|
||||
cleanDataTest()
|
||||
configureProjectionListener()
|
||||
@@ -34,7 +37,7 @@ fun testApplicationWithConfig(
|
||||
) {
|
||||
val logger = KotlinLogging.logger {}
|
||||
testApplication {
|
||||
val conf = ApplicationConfig("application.conf")
|
||||
val conf = ApplicationConfig(CONFIG_FILE_NAME)
|
||||
environment {
|
||||
config = conf
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user