-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kover and gh action for coverage (#2)
* Add kover and gh action for coverage * Add simple test for tracing interceptor * Migrate to libs.versions.toml * Add maven central * Exclude some projects * Add kover project * Add tests for kotlet.json * Add tests for kotlet.metrics * Add tests for kotlet.metrics * Add tests for kotlet.tracing * Fix detekt
- Loading branch information
1 parent
c9e2e0a
commit ab991de
Showing
36 changed files
with
875 additions
and
206 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
|
||
env: | ||
JDK_VERSION: 21 | ||
GRADLE_OPTS: -Dorg.gradle.daemon=false | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
|
@@ -16,8 +17,7 @@ jobs: | |
permissions: | ||
contents: read | ||
checks: write | ||
env: | ||
GRADLE_OPTS: -Dorg.gradle.daemon=false | ||
pull-requests: write | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
|
@@ -28,12 +28,23 @@ jobs: | |
java-version: '${{ env.JDK_VERSION }}' | ||
cache: 'gradle' | ||
- name: Build and Run Tests | ||
run: ./gradlew test | ||
run: ./gradlew test koverXmlReport | ||
- name: Publish Test Report | ||
uses: mikepenz/action-junit-report@v4 | ||
if: success() || failure() # always run even if the previous step fails | ||
with: | ||
report_paths: '**/build/test-results/test/TEST-*.xml' | ||
- name: Publish Kover Report | ||
uses: madrapps/[email protected] | ||
if: success() || failure() # always run even if the previous step fails | ||
with: | ||
paths: | | ||
${{ github.workspace }}/build/reports/kover/report.xml | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
min-coverage-overall: 50 | ||
min-coverage-changed-files: 60 | ||
- name: Coverage verify | ||
run: ./gradlew koverVerify | ||
detekt: | ||
name: Detekt | ||
runs-on: ubuntu-latest | ||
|
@@ -44,8 +55,6 @@ jobs: | |
# only required for workflows in private repositories | ||
actions: read | ||
contents: read | ||
env: | ||
GRADLE_OPTS: -Dorg.gradle.daemon=false | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[versions] | ||
auth0-jwt = "4.4.0" | ||
detekt = "1.23.6" | ||
jakarta = "6.1.0" | ||
jetty = "12.0.10" | ||
kotlin = "2.0.0" | ||
kotlinx-serialization = "1.7.1" | ||
kover = "0.8.2" | ||
mockk = "1.13.12" | ||
opentelemetry = "1.39.0" | ||
opentelemetry-instrumentation-api = "2.5.0" | ||
opentelemetry-semconv = "1.25.0-alpha" | ||
prometheus = "1.3.1" | ||
|
||
[plugins] | ||
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } | ||
jmh = { id = "me.champeau.jmh", version = "0.7.2" } | ||
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } | ||
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } | ||
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } | ||
|
||
[libraries] | ||
|
||
# Jakarta | ||
jakarta-api = { group = "jakarta.servlet", name = "jakarta.servlet-api", version.ref = "jakarta" } | ||
|
||
# JWT | ||
auth0-jwt = { group = "com.auth0", name = "java-jwt", version.ref = "auth0-jwt" } | ||
|
||
# Kotlin | ||
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization" } | ||
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" } | ||
|
||
# Prometheus metrics | ||
prometheus-metrics-core = { group = "io.prometheus", name = "prometheus-metrics-core", version.ref = "prometheus" } | ||
prometheus-metrics-exporter-servlet-jakarta = { group = "io.prometheus", name = "prometheus-metrics-exporter-servlet-jakarta", version.ref = "prometheus" } | ||
|
||
# OpenTelemetry | ||
opentelemetry-api = { group = "io.opentelemetry", name = "opentelemetry-api", version.ref = "opentelemetry" } | ||
opentelemetry-sdk = { group = "io.opentelemetry", name = "opentelemetry-sdk", version.ref = "opentelemetry" } | ||
opentelemetry-exporter-otlp = { group = "io.opentelemetry", name = "opentelemetry-exporter-otlp", version.ref = "opentelemetry" } | ||
opentelemetry-instrumentation-api = { group = "io.opentelemetry.instrumentation", name = "opentelemetry-instrumentation-api", version.ref = "opentelemetry-instrumentation-api" } | ||
opentelemetry-semconv = { group = "io.opentelemetry.semconv", name = "opentelemetry-semconv", version.ref = "opentelemetry-semconv" } | ||
|
||
# Jetty | ||
jetty-server = { group = "org.eclipse.jetty", name = "jetty-server", version.ref = "jetty" } | ||
jetty-ee10-servlet = { group = "org.eclipse.jetty.ee10", name = "jetty-ee10-servlet", version.ref = "jetty" } | ||
|
||
# Testing | ||
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" } |
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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
plugins { | ||
kotlin("jvm") | ||
alias(libs.plugins.kotlin.jvm) | ||
alias(libs.plugins.kotlinx.serialization) | ||
} | ||
|
||
dependencies { | ||
implementation(project(":core")) | ||
compileOnly(libs.jakarta.api) | ||
implementation(libs.kotlinx.serialization.json) | ||
|
||
testImplementation(project(":mocks")) | ||
testImplementation(libs.kotlin.test) | ||
testImplementation(libs.mockk) | ||
testImplementation(libs.jakarta.api) | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
kotlin { | ||
jvmToolchain(21) | ||
} | ||
} |
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,35 @@ | ||
package kotlet | ||
|
||
import io.mockk.verify | ||
import kotlet.mocks.Mocks | ||
import kotlinx.serialization.Serializable | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import kotlin.test.Test | ||
|
||
class HttpCallUnitTest { | ||
@Test | ||
fun `receiveBody must returns deserialized object`() { | ||
val data = "{\"name\":\"test\"}".toByteArray(Charsets.UTF_8) | ||
val call = Mocks.httpCall(method = HttpMethod.GET, data = data) | ||
val obj = call.receiveBody<SimpleBody>() | ||
assertEquals(SimpleBody(name = "test"), obj) | ||
} | ||
|
||
@Test | ||
fun `respondJson must write json`() { | ||
val call = Mocks.httpCall(method = HttpMethod.GET) | ||
call.respondJson(SimpleBody(name = "test")) | ||
|
||
assertEquals("application/json", call.rawResponse.contentType) | ||
assertEquals("{\"name\":\"test\"}", String(call.responseData)) | ||
|
||
verify { | ||
call.rawResponse.contentType = "application/json" | ||
} | ||
} | ||
|
||
@Serializable | ||
private data class SimpleBody(val name: String) | ||
} | ||
|
||
|
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,29 @@ | ||
package kotlet.json | ||
|
||
import kotlinx.serialization.Serializable | ||
import java.io.ByteArrayInputStream | ||
import java.io.ByteArrayOutputStream | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class SerializerUnitTest { | ||
@Test | ||
fun `serialize test`() { | ||
val obj = SimpleObject(name = "test", number = 99) | ||
val stream = ByteArrayOutputStream() | ||
Serializer.serializeToStream(obj, stream) | ||
|
||
val json = stream.toString(Charsets.UTF_8) | ||
assertEquals("{\"name\":\"test\",\"number\":99}", json) | ||
} | ||
|
||
@Test | ||
fun `deserialize test`() { | ||
val stream = ByteArrayInputStream("{\"name\":\"test\",\"number\":99}".toByteArray(Charsets.UTF_8)) | ||
val obj = Serializer.deserialize(stream, SimpleObject::class.java) | ||
assertEquals(SimpleObject(name = "test", number = 99), obj) | ||
} | ||
} | ||
|
||
@Serializable | ||
private data class SimpleObject(val name: String, val number: Int) |
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
Oops, something went wrong.