|
1 | 1 | package io.github.typesafegithub.workflows.jitbindingserver
|
2 | 2 |
|
| 3 | +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords |
3 | 4 | import io.github.typesafegithub.workflows.mavenbinding.TextArtifact
|
4 | 5 | import io.kotest.core.spec.style.FunSpec
|
5 | 6 | import io.kotest.matchers.shouldBe
|
6 | 7 | import io.ktor.client.request.get
|
7 | 8 | import io.ktor.client.statement.bodyAsText
|
8 | 9 | import io.ktor.http.HttpStatusCode
|
9 | 10 | import io.ktor.server.testing.testApplication
|
| 11 | +import io.mockk.every |
| 12 | +import io.mockk.mockk |
| 13 | +import io.mockk.verify |
10 | 14 |
|
11 | 15 | class ArtifactRoutesTest :
|
12 | 16 | FunSpec({
|
@@ -64,5 +68,38 @@ class ArtifactRoutesTest :
|
64 | 68 | response.status shouldBe HttpStatusCode.InternalServerError
|
65 | 69 | }
|
66 | 70 | }
|
| 71 | + |
| 72 | + test("when binding generation fails and then succeeds, and two requests are made") { |
| 73 | + testApplication { |
| 74 | + // Given |
| 75 | + val mockBuildVersionArtifacts = mockk<(ActionCoords) -> Map<String, TextArtifact>?>() |
| 76 | + every { mockBuildVersionArtifacts(any()) } throws |
| 77 | + Exception("An internal error occurred!") andThen |
| 78 | + mapOf("some-action-v4.pom" to TextArtifact { "Some POM contents" }) |
| 79 | + application { |
| 80 | + appModule( |
| 81 | + buildVersionArtifacts = mockBuildVersionArtifacts, |
| 82 | + ) |
| 83 | + } |
| 84 | + |
| 85 | + // When |
| 86 | + val response = client.get("some-owner/some-action/v4/some-action-v4.pom") |
| 87 | + // Then |
| 88 | + response.status shouldBe HttpStatusCode.InternalServerError |
| 89 | + |
| 90 | + // When |
| 91 | + val response2 = client.get("some-owner/some-action/v4/some-action-v4.pom") |
| 92 | + // Then |
| 93 | + // This assertion represents an undesired behavior - it should retry generating the binding |
| 94 | + // and return the actual POM. |
| 95 | + // TODO fix in https://github.com/typesafegithub/github-workflows-kt/issues/1938 |
| 96 | + response2.status shouldBe HttpStatusCode.InternalServerError |
| 97 | + |
| 98 | + // This assertion represents an undesired behavior - it should call the binding generation twice, |
| 99 | + // first with exception, and then when it's successful. |
| 100 | + // TODO fix in https://github.com/typesafegithub/github-workflows-kt/issues/1938 |
| 101 | + verify(exactly = 1) { mockBuildVersionArtifacts(any()) } |
| 102 | + } |
| 103 | + } |
67 | 104 | }
|
68 | 105 | })
|
0 commit comments