Skip to content

Commit

Permalink
test: split unit & integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Prototik committed Jan 9, 2024
1 parent 2424b3e commit 9360a33
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 249 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:

jobs:
build:
name: Build
name: Build & Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand All @@ -29,9 +29,9 @@ jobs:
with:
gradle-version: wrapper
- name: Build
run: gradle -s assemble
run: gradle -s :build
test:
name: Test
name: Integration tests
runs-on: ubuntu-latest
needs: build
strategy:
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
with:
gradle-version: wrapper
- name: Check
run: gradle -s check
run: gradle -s :test :integrationTest
env:
CURSED_PUBLISH_TEST_GRADLE_VERSION: "${{ matrix.gradle }}"
CURSED_PUBLISH_TEST_JAVA_VERSION: "${{ matrix.java }}"
Expand Down
24 changes: 24 additions & 0 deletions .idea/runConfigurations/Run_integration_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 80 additions & 42 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,33 @@ plugins {
alias(libs.plugins.plugin.publish)
}

java {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}
allprojects {
pluginManager.withPlugin("org.gradle.java-base") {
java {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}
}

tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}

tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
apiVersion = KotlinVersion.KOTLIN_1_8
languageVersion = KotlinVersion.KOTLIN_1_8
jvmTarget = JvmTarget.JVM_1_8
javaParameters = true
allWarningsAsErrors = true
freeCompilerArgs.addAll(
"-Xlambdas=indy",
"-Xjvm-default=all",
"-Xemit-jvm-type-annotations",
"-Xnew-inference",
"-Xassertions=jvm"
)
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
apiVersion = KotlinVersion.KOTLIN_1_8
languageVersion = KotlinVersion.KOTLIN_1_8
jvmTarget = JvmTarget.JVM_1_8
javaParameters = true
allWarningsAsErrors = true
freeCompilerArgs.addAll(
"-Xlambdas=indy",
"-Xjvm-default=all",
"-Xemit-jvm-type-annotations",
"-Xnew-inference",
"-Xassertions=jvm"
)
}
}
}

Expand All @@ -43,39 +47,56 @@ repositories {
}

dependencies {
constraints {
implementation(libs.annotations)
}

implementation(platform(embeddedKotlin("bom")))
implementation(platform(libs.kotlinx.coroutines.bom))
implementation(platform(libs.slf4j.bom))
implementation(gradleApi())
implementation(gradleKotlinDsl())
implementation(embeddedKotlin("stdlib"))
implementation(embeddedKotlin("stdlib-jdk8"))
implementation(libs.ktor.client.cio)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.encoding)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.ktor.client.apache5)

compileOnly(libs.annotations)
}

gradlePlugin {
website = "https://github.com/Prototik/CursedPublish"
vcsUrl = "https://github.com/Prototik/CursedPublish"
plugins {
register("cursed-publish") {
id = "rocks.aur.cursed.publish"
implementationClass = "rocks.aur.cursed.publish.CursedPublishPlugin"
description = "Plugin to publish artifacts to the CurseForge portal"
displayName = "Cursed Publish plugin"
tags.addAll("curseforge", "publish", "publication", "upload", "release")
}
}
compileOnlyApi(libs.annotations)
}

testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter()
testType = TestSuiteType.UNIT_TEST
}

val integrationTest by registering(JvmTestSuite::class) {
testType = TestSuiteType.INTEGRATION_TEST

dependencies {
implementation(libs.ktor.client.mock)
implementation(project())
}

targets.configureEach {
testTask {
shouldRunAfter(test)
}
}
}

withType<JvmTestSuite>().configureEach {
val suiteName = name

useJUnitJupiter(libs.versions.junit)

dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom:$embeddedKotlinVersion"))
implementation(platform(libs.kotlinx.coroutines.bom))
implementation(platform(libs.slf4j.bom))
implementation(platform(libs.junit.bom))
implementation(projects.testlib)
implementation.bundle(libs.bundles.kotest)
}

Expand All @@ -85,14 +106,13 @@ testing {
"kotest.framework.parallelism",
Runtime.getRuntime().availableProcessors().coerceAtLeast(2)
)
systemProperty("kotest.framework.classpath.scanning.autoscan.disable", "true")
systemProperty("kotest.framework.classpath.scanning.config.disable", "true")
systemProperty("kotest.framework.config.fqn", "rocks.aur.cursed.publish.test.KotestConfig")

jvmArgumentProviders += CommandLineArgumentProvider {
listOf(
"-Dgradle.build.dir=${project.layout.buildDirectory.get().asFile}",
"-Dgradle.test.suite.name=${this@getting.name}"
"-Dgradle.test.suite.name=${suiteName}"
)
}

Expand All @@ -113,3 +133,21 @@ testing {
}
}
}

gradlePlugin {
website = "https://github.com/Prototik/CursedPublish"
vcsUrl = "https://github.com/Prototik/CursedPublish"
isAutomatedPublishing = true

testSourceSets(sourceSets["integrationTest"])

plugins {
register("cursed-publish") {
id = "rocks.aur.cursed.publish"
implementationClass = "rocks.aur.cursed.publish.CursedPublishPlugin"
description = "Plugin to publish artifacts to the CurseForge portal"
displayName = "Cursed Publish plugin"
tags.addAll("curseforge", "publish", "publication", "upload", "release")
}
}
}
9 changes: 7 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
[versions]
annotations = "24.1.0"
junit = "5.10.1"
kotest = "5.8.0"
kotest-extensions-mockserver = "1.3.0"
kotlinx-coroutines = "1.7.3"
ktor = "2.3.7"
slf4j = "2.0.10"

[libraries]
annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" }
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core-jvm", version.ref = "kotest" }
kotest-extensions-htmlreporter = { module = "io.kotest:kotest-extensions-htmlreporter", version.ref = "kotest" }
kotest-extensions-junitxml = { module = "io.kotest:kotest-extensions-junitxml", version.ref = "kotest" }
kotest-extensions-mockserver = { module = "io.kotest.extensions:kotest-extensions-mockserver", version.ref = "kotest-extensions-mockserver" }
kotest-framework-datatest = { module = "io.kotest:kotest-framework-datatest-jvm", version.ref = "kotest" }
kotest-property = { module = "io.kotest:kotest-property-jvm", version.ref = "kotest" }
kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5-jvm", version.ref = "kotest" }
ktor-client-apache5 = { module = "io.ktor:ktor-client-apache5-jvm", version.ref = "ktor" }
kotlinx-coroutines-bom = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-bom", version.ref = "kotlinx-coroutines" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio-jvm", version.ref = "ktor" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation-jvm", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core-jvm", version.ref = "ktor" }
ktor-client-encoding = { module = "io.ktor:ktor-client-encoding-jvm", version.ref = "ktor" }
ktor-client-mock = { module = "io.ktor:ktor-client-mock-jvm", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json-jvm", version.ref = "ktor" }
slf4j-bom = { module = "org.slf4j:slf4j-bom", version.ref = "slf4j" }

[bundles]
kotest = [
Expand Down
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

rootProject.name = "cursed-publish"

include(":testlib")

gradleEnterprise {
if (System.getenv("CI") != null) {
buildScan {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ sealed class GradleBuildScriptSpec(
`when`(gameVersionTypesRequest).respond(
HttpResponse.response()
.withBody(
GameVersionTypesSpec.stream().bufferedReader().readText(),
ModelFixtures.gameVersionTypes().bufferedReader().readText(),
MediaType.APPLICATION_JSON_UTF_8
)
)

`when`(gameVersionsRequest).respond(
HttpResponse.response()
.withBody(
GameVersionsSpec.stream().bufferedReader().readText(),
ModelFixtures.gameVersions().bufferedReader().readText(),
MediaType.APPLICATION_JSON_UTF_8
)
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/rocks/aur/cursed/publish/CursedPublishSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package rocks.aur.cursed.publish

import io.ktor.client.*
import io.ktor.client.engine.*
import io.ktor.client.engine.apache5.*
import io.ktor.client.engine.cio.*
import org.gradle.api.*
import org.gradle.api.provider.*
import org.gradle.api.tasks.*
Expand Down Expand Up @@ -110,7 +110,7 @@ interface CursedPublishSpec {

object Default : HttpClientInitializer {
override fun create(config: Action<in HttpClientConfig<*>>): HttpClient {
return HttpClient(Apache5) {
return HttpClient(CIO) {
config.execute(this)
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit 9360a33

Please sign in to comment.