Skip to content

Commit 76129a2

Browse files
authored
test(server): add more tests with mocked versioned artifact building (#1931)
So that we don't rely solely on the end-to-end tests that call the server via the Kotlin script. Having such tests should give us a shorter feedback loop via Gradle if there's an obvious regression.
1 parent 803d578 commit 76129a2

File tree

1 file changed

+47
-0
lines changed
  • jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver

1 file changed

+47
-0
lines changed

jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ArtifactRoutesTest.kt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,62 @@
11
package io.github.typesafegithub.workflows.jitbindingserver
22

3+
import io.github.typesafegithub.workflows.mavenbinding.TextArtifact
34
import io.kotest.core.spec.style.FunSpec
45
import io.kotest.matchers.shouldBe
56
import io.ktor.client.request.get
7+
import io.ktor.client.statement.bodyAsText
68
import io.ktor.http.HttpStatusCode
79
import io.ktor.server.routing.routing
810
import io.ktor.server.testing.testApplication
911

1012
class ArtifactRoutesTest :
1113
FunSpec({
1214
context("artifacts for a given version") {
15+
test("when some artifacts were generated") {
16+
testApplication {
17+
// Given
18+
application {
19+
routing {
20+
artifactRoutes(
21+
buildBindingsCache(
22+
buildVersionArtifacts = {
23+
mapOf("some-action-v4.pom" to TextArtifact { "Some POM contents" })
24+
},
25+
),
26+
)
27+
}
28+
}
29+
30+
// When
31+
val response = client.get("some-owner/some-action/v4/some-action-v4.pom")
32+
33+
// Then
34+
response.status shouldBe HttpStatusCode.OK
35+
response.bodyAsText() shouldBe "Some POM contents"
36+
}
37+
}
38+
39+
test("when no artifacts could be generated") {
40+
testApplication {
41+
// Given
42+
application {
43+
routing {
44+
artifactRoutes(
45+
buildBindingsCache(
46+
buildVersionArtifacts = { null },
47+
),
48+
)
49+
}
50+
}
51+
52+
// When
53+
val response = client.get("some-owner/some-action/v4/some-action-v4.pom")
54+
55+
// Then
56+
response.status shouldBe HttpStatusCode.NotFound
57+
}
58+
}
59+
1360
test("when binding generation fails") {
1461
testApplication {
1562
// Given

0 commit comments

Comments
 (0)