From 17c91fee1050b711946bf79edc728fd89c6481bd Mon Sep 17 00:00:00 2001 From: Craig Atkinson Date: Mon, 15 Apr 2024 08:29:23 -0500 Subject: [PATCH] Upgrading to Wiremock 3 and rewriting a couple Wiremock kotest tests into JUnit for ease --- gradle.properties | 2 +- server/notification/github/build.gradle | 4 + .../github/WireMockTestListener.kt | 23 -- .../github/comment/GitHubCommentClientSpec.kt | 119 ------ .../github/comment/GitHubCommentClientTest.kt | 120 ++++++ .../comment/GitHubCommentServiceSpec.kt | 375 ----------------- .../comment/GitHubCommentServiceTest.kt | 386 ++++++++++++++++++ .../github/GitHubWireMockStubber.kt | 40 +- ...tadataPullRequestCommentApplicationTest.kt | 3 +- ...GitHubPullRequestCommentApplicationTest.kt | 3 +- 10 files changed, 535 insertions(+), 540 deletions(-) delete mode 100644 server/notification/github/src/test/kotlin/projektor/notification/github/WireMockTestListener.kt delete mode 100644 server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentClientSpec.kt create mode 100644 server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentClientTest.kt delete mode 100644 server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentServiceSpec.kt create mode 100644 server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentServiceTest.kt diff --git a/gradle.properties b/gradle.properties index 6a00f780d..b2fb3c16d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ kotlin_version=1.9.22 kotest_version=5.8.1 spockVersion=2.3-groovy-3.0 strikt_version=0.34.1 -wiremockVersion=2.35.2 +wiremockVersion=3.0.1 github_api_version=1.321 logbackVersion=1.5.5 diff --git a/server/notification/github/build.gradle b/server/notification/github/build.gradle index c283c2b1b..a6cf18455 100644 --- a/server/notification/github/build.gradle +++ b/server/notification/github/build.gradle @@ -17,5 +17,9 @@ dependencies { testImplementation "com.github.tomakehurst:wiremock-jre8:$wiremockVersion" + testImplementation(platform('org.junit:junit-bom:5.10.2')) + testImplementation('org.junit.jupiter:junit-jupiter') + testRuntimeOnly('org.junit.platform:junit-platform-launcher') + testFixturesImplementation "com.github.tomakehurst:wiremock-jre8:$wiremockVersion" } diff --git a/server/notification/github/src/test/kotlin/projektor/notification/github/WireMockTestListener.kt b/server/notification/github/src/test/kotlin/projektor/notification/github/WireMockTestListener.kt deleted file mode 100644 index f8ce00adc..000000000 --- a/server/notification/github/src/test/kotlin/projektor/notification/github/WireMockTestListener.kt +++ /dev/null @@ -1,23 +0,0 @@ -package projektor.notification.github - -import com.github.tomakehurst.wiremock.WireMockServer -import io.kotest.core.listeners.TestListener -import io.kotest.core.test.TestCase -import io.kotest.core.test.TestResult - -class WireMockTestListener(private val wireMockServer: WireMockServer) : TestListener { - override suspend fun beforeTest(testCase: TestCase) { - wireMockServer.start() - } - - override suspend fun beforeEach(testCase: TestCase) { - wireMockServer.resetAll() - } - - override suspend fun afterTest( - testCase: TestCase, - result: TestResult, - ) { - wireMockServer.stop() - } -} diff --git a/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentClientSpec.kt b/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentClientSpec.kt deleted file mode 100644 index 5ffec978c..000000000 --- a/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentClientSpec.kt +++ /dev/null @@ -1,119 +0,0 @@ -package projektor.notification.github.comment - -import com.github.tomakehurst.wiremock.WireMockServer -import com.github.tomakehurst.wiremock.core.WireMockConfiguration -import io.kotest.core.spec.style.StringSpec -import projektor.notification.github.GitHubClientConfig -import projektor.notification.github.GitHubWireMockStubber -import projektor.notification.github.WireMockTestListener -import projektor.notification.github.auth.MockJwtProvider -import strikt.api.expectThat -import strikt.assertions.contains -import strikt.assertions.hasSize -import strikt.assertions.isEqualTo -import strikt.assertions.isNotNull -import strikt.assertions.isNull -import kotlin.test.assertNotNull - -class GitHubCommentClientSpec : StringSpec() { - private val wireMockServer = WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()) - private val gitHubWireMockStubber = GitHubWireMockStubber(wireMockServer) - - override fun listeners() = listOf(WireMockTestListener(wireMockServer)) - - private val jwtToken = "my-jwt" - private val jwtProvider = MockJwtProvider(jwtToken) - - init { - "should create comment on issue" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val gitHubCommentClient = GitHubCommentClient(clientConfig, jwtProvider) - - val orgName = "my-org" - val repoName = "my-repo" - val issueId = 12 - - val commentText = "Here is my comment" - - gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) - - gitHubWireMockStubber.stubGetIssue(orgName, repoName, issueId) - gitHubWireMockStubber.stubAddComment(orgName, repoName, issueId) - - val repository = gitHubCommentClient.getRepository(orgName, repoName) - assertNotNull(repository) - gitHubCommentClient.addComment(repository, issueId, commentText) - - val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, issueId) - expectThat(addCommentRequestBodies).hasSize(1) - - expectThat(addCommentRequestBodies[0]).contains(commentText) - } - - "should return null when trying to get repository that does not have app enabled" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val gitHubCommentClient = GitHubCommentClient(clientConfig, jwtProvider) - - val orgName = "my-org" - val repoName = "app-not-installed-repo" - - gitHubWireMockStubber.stubApp() - gitHubWireMockStubber.stubGetRepoInstallationNotFound(orgName, repoName) - - val repository = gitHubCommentClient.getRepository(orgName, repoName) - expectThat(repository).isNull() - } - - "when open PR exists for branch should find the PR number" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val gitHubCommentClient = GitHubCommentClient(clientConfig, jwtProvider) - - val orgName = "my-org" - val repoName = "my-repo" - - gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) - - gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("the-branch", "another-branch")) - - val repository = gitHubCommentClient.getRepository(orgName, repoName) - assertNotNull(repository) - - val pullRequestNumber = gitHubCommentClient.findOpenPullRequests(repository, "the-branch", null) - expectThat(pullRequestNumber).isNotNull().isEqualTo(1) - } - - "when no open PR for branch should return null for PR number" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val gitHubCommentClient = GitHubCommentClient(clientConfig, jwtProvider) - - val orgName = "my-org" - val repoName = "my-repo" - - gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) - - gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("the-branch", "another-branch")) - - val repository = gitHubCommentClient.getRepository(orgName, repoName) - assertNotNull(repository) - - val pullRequestNumber = gitHubCommentClient.findOpenPullRequests(repository, "some-branch", null) - expectThat(pullRequestNumber).isNull() - } - } -} diff --git a/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentClientTest.kt b/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentClientTest.kt new file mode 100644 index 000000000..163a6e0d3 --- /dev/null +++ b/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentClientTest.kt @@ -0,0 +1,120 @@ +package projektor.notification.github.comment + +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import org.junit.jupiter.api.Test +import projektor.notification.github.GitHubClientConfig +import projektor.notification.github.GitHubWireMockStubber +import projektor.notification.github.auth.MockJwtProvider +import strikt.api.expectThat +import strikt.assertions.* +import kotlin.test.assertNotNull + +@WireMockTest +class GitHubCommentClientTest { + private val jwtToken = "my-jwt" + private val jwtProvider = MockJwtProvider(jwtToken) + + @Test + fun `should create comment on issue`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val gitHubCommentClient = GitHubCommentClient(clientConfig, jwtProvider) + + val orgName = "my-org" + val repoName = "my-repo" + val issueId = 12 + + val commentText = "Here is my comment" + + gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) + + gitHubWireMockStubber.stubGetIssue(orgName, repoName, issueId) + gitHubWireMockStubber.stubAddComment(orgName, repoName, issueId) + + val repository = gitHubCommentClient.getRepository(orgName, repoName) + assertNotNull(repository) + gitHubCommentClient.addComment(repository, issueId, commentText) + + val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, issueId) + expectThat(addCommentRequestBodies).hasSize(1) + + expectThat(addCommentRequestBodies[0]).contains(commentText) + } + + @Test + fun `should return null when trying to get repository that does not have app enabled`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val gitHubCommentClient = GitHubCommentClient(clientConfig, jwtProvider) + + val orgName = "my-org" + val repoName = "app-not-installed-repo" + + gitHubWireMockStubber.stubApp() + gitHubWireMockStubber.stubGetRepoInstallationNotFound(orgName, repoName) + + val repository = gitHubCommentClient.getRepository(orgName, repoName) + expectThat(repository).isNull() + } + + @Test + fun `when open PR exists for branch should find the PR number`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val gitHubCommentClient = GitHubCommentClient(clientConfig, jwtProvider) + + val orgName = "my-org" + val repoName = "my-repo" + + gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) + + gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("the-branch", "another-branch")) + + val repository = gitHubCommentClient.getRepository(orgName, repoName) + assertNotNull(repository) + + val pullRequestNumber = gitHubCommentClient.findOpenPullRequests(repository, "the-branch", null) + expectThat(pullRequestNumber).isNotNull().isEqualTo(1) + } + + @Test + fun `when no open PR for branch should return null for PR number`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val gitHubCommentClient = GitHubCommentClient(clientConfig, jwtProvider) + + val orgName = "my-org" + val repoName = "my-repo" + + gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) + + gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("the-branch", "another-branch")) + + val repository = gitHubCommentClient.getRepository(orgName, repoName) + assertNotNull(repository) + + val pullRequestNumber = gitHubCommentClient.findOpenPullRequests(repository, "some-branch", null) + expectThat(pullRequestNumber).isNull() + } +} diff --git a/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentServiceSpec.kt b/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentServiceSpec.kt deleted file mode 100644 index 300b59f78..000000000 --- a/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentServiceSpec.kt +++ /dev/null @@ -1,375 +0,0 @@ -package projektor.notification.github.comment - -import com.github.tomakehurst.wiremock.WireMockServer -import com.github.tomakehurst.wiremock.core.WireMockConfiguration -import io.kotest.core.spec.style.StringSpec -import projektor.notification.github.GitHubClientConfig -import projektor.notification.github.GitHubWireMockStubber -import projektor.notification.github.WireMockTestListener -import projektor.notification.github.auth.MockJwtProvider -import strikt.api.expectThat -import strikt.assertions.contains -import strikt.assertions.hasSize -import strikt.assertions.isEqualTo -import strikt.assertions.isNull -import java.time.LocalDate -import java.time.LocalDateTime -import java.time.LocalTime -import kotlin.test.assertNotNull - -class GitHubCommentServiceSpec : StringSpec() { - private val wireMockServer = WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()) - private val gitHubWireMockStubber = GitHubWireMockStubber(wireMockServer) - - override fun listeners() = listOf(WireMockTestListener(wireMockServer)) - - private val jwtToken = "my-jwt" - private val jwtProvider = MockJwtProvider(jwtToken) - - init { - "should add new comment when one does not exist" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val commentClient = GitHubCommentClient(clientConfig, jwtProvider) - val commentService = GitHubCommentService(commentClient) - - val orgName = "my-org" - val repoName = "my-repo" - val branchName = "my-branch" - val pullRequestNumber = 2 - val report = - ReportCommentData( - projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", - git = - ReportCommentGitData( - orgName = orgName, - repoName = repoName, - branchName = branchName, - ), - publicId = "V1BMYK93MTNR", - createdDate = - LocalDateTime.of( - LocalDate.of(2020, 12, 16), - LocalTime.of(14, 30), - ), - passed = true, - failedTestCount = 0, - totalTestCount = 25, - coverage = null, - performance = null, - project = null, - ) - - gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) - gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("another-branch", branchName)) - gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) - gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) - gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) - - val pullRequest = commentService.upsertReportComment(report, "12345") - assertNotNull(pullRequest) - expectThat(pullRequest.orgName).isEqualTo(orgName) - expectThat(pullRequest.repoName).isEqualTo(repoName) - expectThat(pullRequest.number).isEqualTo(pullRequestNumber) - - val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) - expectThat(addCommentRequestBodies).hasSize(1) - expectThat(addCommentRequestBodies[0]).contains("V1BMYK93MTNR") - - val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) - expectThat(updateCommentRequestBodies).hasSize(0) - } - - "should update comment when one exists" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val commentClient = GitHubCommentClient(clientConfig, jwtProvider) - val commentService = GitHubCommentService(commentClient) - - val orgName = "my-org" - val repoName = "my-repo" - val branchName = "my-branch" - val pullRequestNumber = 2 - val report = - ReportCommentData( - projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", - git = - ReportCommentGitData( - orgName = orgName, - repoName = repoName, - branchName = branchName, - ), - publicId = "V1BMYK93MTNR", - createdDate = - LocalDateTime.of( - LocalDate.of(2020, 12, 16), - LocalTime.of(14, 30), - ), - passed = true, - failedTestCount = 0, - totalTestCount = 25, - coverage = null, - performance = null, - project = null, - ) - - gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) - gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("another-branch", branchName)) - gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) - val commentId = 3 - gitHubWireMockStubber.stubListComments( - orgName, - repoName, - pullRequestNumber, - listOf("A comment", "Another comment", GitHubCommentCreator.HEADER_TEXT), - ) - gitHubWireMockStubber.stubGetComment(orgName, repoName, pullRequestNumber, commentId, GitHubCommentCreator.HEADER_TEXT) - gitHubWireMockStubber.stubUpdateComment(orgName, repoName, pullRequestNumber, commentId) - - val pullRequest = commentService.upsertReportComment(report, "12345") - assertNotNull(pullRequest) - expectThat(pullRequest.orgName).isEqualTo(orgName) - expectThat(pullRequest.repoName).isEqualTo(repoName) - expectThat(pullRequest.number).isEqualTo(pullRequestNumber) - - val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) - expectThat(addCommentRequestBodies).hasSize(0) - - val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, commentId) - expectThat(updateCommentRequestBodies).hasSize(1) - expectThat(updateCommentRequestBodies[0]).contains("V1BMYK93MTNR") - } - - "should return null when no pull request with branch name" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val commentClient = GitHubCommentClient(clientConfig, jwtProvider) - val commentService = GitHubCommentService(commentClient) - - val orgName = "my-org" - val repoName = "my-repo" - val branchName = "my-branch" - val pullRequestNumber = 2 - val report = - ReportCommentData( - projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", - git = - ReportCommentGitData( - orgName = orgName, - repoName = repoName, - branchName = branchName, - ), - publicId = "V1BMYK93MTNR", - createdDate = - LocalDateTime.of( - LocalDate.of(2020, 12, 16), - LocalTime.of(14, 30), - ), - passed = true, - failedTestCount = 0, - totalTestCount = 25, - coverage = null, - performance = null, - project = null, - ) - - gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) - gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("another-branch", "yet-another-branch")) - gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) - gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) - gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) - - val pullRequest = commentService.upsertReportComment(report, "12345") - expectThat(pullRequest).isNull() - - val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) - expectThat(addCommentRequestBodies).hasSize(0) - - val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) - expectThat(updateCommentRequestBodies).hasSize(0) - } - - "should find pull request by commit SHA" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val commentClient = GitHubCommentClient(clientConfig, jwtProvider) - val commentService = GitHubCommentService(commentClient) - - val orgName = "my-org" - val repoName = "my-repo" - val branchName = "my-branch" - val pullRequestNumber = 2 - val sha = "123456789" - val report = - ReportCommentData( - projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", - git = - ReportCommentGitData( - orgName = orgName, - repoName = repoName, - branchName = branchName, - commitSha = sha, - ), - publicId = "V1BMYK93MTNR", - createdDate = - LocalDateTime.of( - LocalDate.of(2020, 12, 16), - LocalTime.of(14, 30), - ), - passed = true, - failedTestCount = 0, - totalTestCount = 25, - coverage = null, - performance = null, - project = null, - ) - - gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) - gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("branch-1", "branch-2"), listOf("sha1", sha)) - gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) - gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) - gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) - - val pullRequest = commentService.upsertReportComment(report, "12345") - assertNotNull(pullRequest) - expectThat(pullRequest.orgName).isEqualTo(orgName) - expectThat(pullRequest.repoName).isEqualTo(repoName) - expectThat(pullRequest.number).isEqualTo(pullRequestNumber) - - val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) - expectThat(addCommentRequestBodies).hasSize(1) - expectThat(addCommentRequestBodies[0]).contains("V1BMYK93MTNR") - - val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) - expectThat(updateCommentRequestBodies).hasSize(0) - } - - "should find pull request by commit SHA when no branch included" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val commentClient = GitHubCommentClient(clientConfig, jwtProvider) - val commentService = GitHubCommentService(commentClient) - - val orgName = "my-org" - val repoName = "my-repo" - val branchName = null - val pullRequestNumber = 2 - val sha = "123456789" - val report = - ReportCommentData( - projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", - git = - ReportCommentGitData( - orgName = orgName, - repoName = repoName, - branchName = branchName, - commitSha = sha, - ), - publicId = "V1BMYK93MTNR", - createdDate = - LocalDateTime.of( - LocalDate.of(2020, 12, 16), - LocalTime.of(14, 30), - ), - passed = true, - failedTestCount = 0, - totalTestCount = 25, - coverage = null, - performance = null, - project = null, - ) - - gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) - gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("branch-1", "branch-2"), listOf("sha1", sha)) - gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) - gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) - gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) - - val pullRequest = commentService.upsertReportComment(report, "12345") - assertNotNull(pullRequest) - expectThat(pullRequest.orgName).isEqualTo(orgName) - expectThat(pullRequest.repoName).isEqualTo(repoName) - expectThat(pullRequest.number).isEqualTo(pullRequestNumber) - - val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) - expectThat(addCommentRequestBodies).hasSize(1) - expectThat(addCommentRequestBodies[0]).contains("V1BMYK93MTNR") - - val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) - expectThat(updateCommentRequestBodies).hasSize(0) - } - - "when pull request number passed in should use that" { - val gitHubApiUrl = "http://localhost:${wireMockServer.port()}/" - val clientConfig = - GitHubClientConfig( - gitHubApiUrl, - ) - val commentClient = GitHubCommentClient(clientConfig, jwtProvider) - val commentService = GitHubCommentService(commentClient) - - val orgName = "my-org" - val repoName = "my-repo" - val branchName = "my-branch" - val pullRequestNumber = 2 - val sha = "123456789" - val report = - ReportCommentData( - projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", - git = - ReportCommentGitData( - orgName = orgName, - repoName = repoName, - branchName = branchName, - commitSha = sha, - pullRequestNumber = pullRequestNumber, - ), - publicId = "V1BMYK93MTNR", - createdDate = - LocalDateTime.of( - LocalDate.of(2020, 12, 16), - LocalTime.of(14, 30), - ), - passed = true, - failedTestCount = 0, - totalTestCount = 25, - coverage = null, - performance = null, - project = null, - ) - - gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) - gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) - gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) - gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) - - val pullRequest = commentService.upsertReportComment(report, "12345") - assertNotNull(pullRequest) - expectThat(pullRequest.orgName).isEqualTo(orgName) - expectThat(pullRequest.repoName).isEqualTo(repoName) - expectThat(pullRequest.number).isEqualTo(pullRequestNumber) - - val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) - expectThat(addCommentRequestBodies).hasSize(1) - expectThat(addCommentRequestBodies[0]).contains("V1BMYK93MTNR") - - val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) - expectThat(updateCommentRequestBodies).hasSize(0) - } - } -} diff --git a/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentServiceTest.kt b/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentServiceTest.kt new file mode 100644 index 000000000..7f2f2215f --- /dev/null +++ b/server/notification/github/src/test/kotlin/projektor/notification/github/comment/GitHubCommentServiceTest.kt @@ -0,0 +1,386 @@ +package projektor.notification.github.comment + +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import org.junit.jupiter.api.Test +import projektor.notification.github.GitHubClientConfig +import projektor.notification.github.GitHubWireMockStubber +import projektor.notification.github.auth.MockJwtProvider +import strikt.api.expectThat +import strikt.assertions.contains +import strikt.assertions.hasSize +import strikt.assertions.isEqualTo +import strikt.assertions.isNull +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import kotlin.test.assertNotNull + +@WireMockTest +class GitHubCommentServiceTest { + private val jwtToken = "my-jwt" + private val jwtProvider = MockJwtProvider(jwtToken) + + @Test + fun `should add new comment when one does not exist`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val commentClient = GitHubCommentClient(clientConfig, jwtProvider) + val commentService = GitHubCommentService(commentClient) + + val orgName = "my-org" + val repoName = "my-repo" + val branchName = "my-branch" + val pullRequestNumber = 2 + val report = + ReportCommentData( + projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", + git = + ReportCommentGitData( + orgName = orgName, + repoName = repoName, + branchName = branchName, + ), + publicId = "V1BMYK93MTNR", + createdDate = + LocalDateTime.of( + LocalDate.of(2020, 12, 16), + LocalTime.of(14, 30), + ), + passed = true, + failedTestCount = 0, + totalTestCount = 25, + coverage = null, + performance = null, + project = null, + ) + + gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) + gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("another-branch", branchName)) + gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) + gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) + gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) + + val pullRequest = commentService.upsertReportComment(report, "12345") + assertNotNull(pullRequest) + expectThat(pullRequest.orgName).isEqualTo(orgName) + expectThat(pullRequest.repoName).isEqualTo(repoName) + expectThat(pullRequest.number).isEqualTo(pullRequestNumber) + + val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) + expectThat(addCommentRequestBodies).hasSize(1) + expectThat(addCommentRequestBodies[0]).contains("V1BMYK93MTNR") + + val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) + expectThat(updateCommentRequestBodies).hasSize(0) + } + + @Test + fun `should update comment when one exists`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val commentClient = GitHubCommentClient(clientConfig, jwtProvider) + val commentService = GitHubCommentService(commentClient) + + val orgName = "my-org" + val repoName = "my-repo" + val branchName = "my-branch" + val pullRequestNumber = 2 + val report = + ReportCommentData( + projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", + git = + ReportCommentGitData( + orgName = orgName, + repoName = repoName, + branchName = branchName, + ), + publicId = "V1BMYK93MTNR", + createdDate = + LocalDateTime.of( + LocalDate.of(2020, 12, 16), + LocalTime.of(14, 30), + ), + passed = true, + failedTestCount = 0, + totalTestCount = 25, + coverage = null, + performance = null, + project = null, + ) + + gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) + gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("another-branch", branchName)) + gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) + val commentId = 3 + gitHubWireMockStubber.stubListComments( + orgName, + repoName, + pullRequestNumber, + listOf("A comment", "Another comment", GitHubCommentCreator.HEADER_TEXT), + ) + gitHubWireMockStubber.stubGetComment(orgName, repoName, pullRequestNumber, commentId, GitHubCommentCreator.HEADER_TEXT) + gitHubWireMockStubber.stubUpdateComment(orgName, repoName, pullRequestNumber, commentId) + + val pullRequest = commentService.upsertReportComment(report, "12345") + assertNotNull(pullRequest) + expectThat(pullRequest.orgName).isEqualTo(orgName) + expectThat(pullRequest.repoName).isEqualTo(repoName) + expectThat(pullRequest.number).isEqualTo(pullRequestNumber) + + val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) + expectThat(addCommentRequestBodies).hasSize(0) + + val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, commentId) + expectThat(updateCommentRequestBodies).hasSize(1) + expectThat(updateCommentRequestBodies[0]).contains("V1BMYK93MTNR") + } + + @Test + fun `should return null when no pull request with branch name`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val commentClient = GitHubCommentClient(clientConfig, jwtProvider) + val commentService = GitHubCommentService(commentClient) + + val orgName = "my-org" + val repoName = "my-repo" + val branchName = "my-branch" + val pullRequestNumber = 2 + val report = + ReportCommentData( + projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", + git = + ReportCommentGitData( + orgName = orgName, + repoName = repoName, + branchName = branchName, + ), + publicId = "V1BMYK93MTNR", + createdDate = + LocalDateTime.of( + LocalDate.of(2020, 12, 16), + LocalTime.of(14, 30), + ), + passed = true, + failedTestCount = 0, + totalTestCount = 25, + coverage = null, + performance = null, + project = null, + ) + + gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) + gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("another-branch", "yet-another-branch")) + gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) + gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) + gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) + + val pullRequest = commentService.upsertReportComment(report, "12345") + expectThat(pullRequest).isNull() + + val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) + expectThat(addCommentRequestBodies).hasSize(0) + + val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) + expectThat(updateCommentRequestBodies).hasSize(0) + } + + @Test + fun `should find pull request by commit SHA`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val commentClient = GitHubCommentClient(clientConfig, jwtProvider) + val commentService = GitHubCommentService(commentClient) + + val orgName = "my-org" + val repoName = "my-repo" + val branchName = "my-branch" + val pullRequestNumber = 2 + val sha = "123456789" + val report = + ReportCommentData( + projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", + git = + ReportCommentGitData( + orgName = orgName, + repoName = repoName, + branchName = branchName, + commitSha = sha, + ), + publicId = "V1BMYK93MTNR", + createdDate = + LocalDateTime.of( + LocalDate.of(2020, 12, 16), + LocalTime.of(14, 30), + ), + passed = true, + failedTestCount = 0, + totalTestCount = 25, + coverage = null, + performance = null, + project = null, + ) + + gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) + gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("branch-1", "branch-2"), listOf("sha1", sha)) + gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) + gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) + gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) + + val pullRequest = commentService.upsertReportComment(report, "12345") + assertNotNull(pullRequest) + expectThat(pullRequest.orgName).isEqualTo(orgName) + expectThat(pullRequest.repoName).isEqualTo(repoName) + expectThat(pullRequest.number).isEqualTo(pullRequestNumber) + + val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) + expectThat(addCommentRequestBodies).hasSize(1) + expectThat(addCommentRequestBodies[0]).contains("V1BMYK93MTNR") + + val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) + expectThat(updateCommentRequestBodies).hasSize(0) + } + + @Test + fun `should find pull request by commit SHA when no branch included`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val commentClient = GitHubCommentClient(clientConfig, jwtProvider) + val commentService = GitHubCommentService(commentClient) + + val orgName = "my-org" + val repoName = "my-repo" + val branchName = null + val pullRequestNumber = 2 + val sha = "123456789" + val report = + ReportCommentData( + projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", + git = + ReportCommentGitData( + orgName = orgName, + repoName = repoName, + branchName = branchName, + commitSha = sha, + ), + publicId = "V1BMYK93MTNR", + createdDate = + LocalDateTime.of( + LocalDate.of(2020, 12, 16), + LocalTime.of(14, 30), + ), + passed = true, + failedTestCount = 0, + totalTestCount = 25, + coverage = null, + performance = null, + project = null, + ) + + gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) + gitHubWireMockStubber.stubListPullRequests(orgName, repoName, listOf("branch-1", "branch-2"), listOf("sha1", sha)) + gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) + gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) + gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) + + val pullRequest = commentService.upsertReportComment(report, "12345") + assertNotNull(pullRequest) + expectThat(pullRequest.orgName).isEqualTo(orgName) + expectThat(pullRequest.repoName).isEqualTo(repoName) + expectThat(pullRequest.number).isEqualTo(pullRequestNumber) + + val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) + expectThat(addCommentRequestBodies).hasSize(1) + expectThat(addCommentRequestBodies[0]).contains("V1BMYK93MTNR") + + val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) + expectThat(updateCommentRequestBodies).hasSize(0) + } + + @Test + fun `when pull request number passed in should use that`(wmRuntimeInfo: WireMockRuntimeInfo) { + val gitHubWireMockStubber = GitHubWireMockStubber(wmRuntimeInfo.wireMock) + + val gitHubApiUrl = "http://localhost:${wmRuntimeInfo.httpPort}/" + val clientConfig = + GitHubClientConfig( + gitHubApiUrl, + ) + val commentClient = GitHubCommentClient(clientConfig, jwtProvider) + val commentService = GitHubCommentService(commentClient) + + val orgName = "my-org" + val repoName = "my-repo" + val branchName = "my-branch" + val pullRequestNumber = 2 + val sha = "123456789" + val report = + ReportCommentData( + projektorServerBaseUrl = "https://projektorlive.herokuapp.com/", + git = + ReportCommentGitData( + orgName = orgName, + repoName = repoName, + branchName = branchName, + commitSha = sha, + pullRequestNumber = pullRequestNumber, + ), + publicId = "V1BMYK93MTNR", + createdDate = + LocalDateTime.of( + LocalDate.of(2020, 12, 16), + LocalTime.of(14, 30), + ), + passed = true, + failedTestCount = 0, + totalTestCount = 25, + coverage = null, + performance = null, + project = null, + ) + + gitHubWireMockStubber.stubRepositoryRequests(orgName, repoName) + gitHubWireMockStubber.stubGetIssue(orgName, repoName, pullRequestNumber) + gitHubWireMockStubber.stubListComments(orgName, repoName, pullRequestNumber, listOf("Some other comment")) + gitHubWireMockStubber.stubAddComment(orgName, repoName, pullRequestNumber) + + val pullRequest = commentService.upsertReportComment(report, "12345") + assertNotNull(pullRequest) + expectThat(pullRequest.orgName).isEqualTo(orgName) + expectThat(pullRequest.repoName).isEqualTo(repoName) + expectThat(pullRequest.number).isEqualTo(pullRequestNumber) + + val addCommentRequestBodies = gitHubWireMockStubber.findAddCommentRequestBodies(orgName, repoName, pullRequestNumber) + expectThat(addCommentRequestBodies).hasSize(1) + expectThat(addCommentRequestBodies[0]).contains("V1BMYK93MTNR") + + val updateCommentRequestBodies = gitHubWireMockStubber.findUpdateCommentRequestBodies(orgName, repoName, 1) + expectThat(updateCommentRequestBodies).hasSize(0) + } +} diff --git a/server/notification/github/src/testFixtures/kotlin/projektor/notification/github/GitHubWireMockStubber.kt b/server/notification/github/src/testFixtures/kotlin/projektor/notification/github/GitHubWireMockStubber.kt index 6877b71da..38fe4c70d 100644 --- a/server/notification/github/src/testFixtures/kotlin/projektor/notification/github/GitHubWireMockStubber.kt +++ b/server/notification/github/src/testFixtures/kotlin/projektor/notification/github/GitHubWireMockStubber.kt @@ -1,6 +1,6 @@ package projektor.notification.github -import com.github.tomakehurst.wiremock.WireMockServer +import com.github.tomakehurst.wiremock.client.WireMock import com.github.tomakehurst.wiremock.client.WireMock.aResponse import com.github.tomakehurst.wiremock.client.WireMock.get import com.github.tomakehurst.wiremock.client.WireMock.patch @@ -9,7 +9,7 @@ import com.github.tomakehurst.wiremock.client.WireMock.post import com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo -class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { +class GitHubWireMockStubber(private val wireMockServer: WireMock) { fun stubRepositoryRequests( orgName: String, repoName: String, @@ -26,7 +26,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { } fun stubApp() { - wireMockServer.stubFor( + wireMockServer.register( get(urlEqualTo("/app")) .willReturn( aResponse().withBody( @@ -72,7 +72,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { repoName: String, installationId: Int, ) { - wireMockServer.stubFor( + wireMockServer.register( get(urlEqualTo("/repos/$orgName/$repoName/installation")) .willReturn( aResponse().withBody( @@ -125,10 +125,10 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { orgName: String, repoName: String, ) { - wireMockServer.stubFor( + wireMockServer.register( get(urlEqualTo("/repos/$orgName/$repoName/installation")) .willReturn( - aResponse().withStatus(404), + aResponse().withStatus(404).withBody(""), ), ) } @@ -138,7 +138,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { token: String, repositoryId: Int, ) { - wireMockServer.stubFor( + wireMockServer.register( post(urlEqualTo("/app/installations/$installationId/access_tokens")) .willReturn( aResponse().withBody( @@ -236,7 +236,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { repoName: String, repositoryId: Int, ) { - wireMockServer.stubFor( + wireMockServer.register( get(urlEqualTo("/repos/$orgName/$repoName")) .willReturn( aResponse().withBody( @@ -472,7 +472,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { repoName: String, issueId: Int, ) { - wireMockServer.stubFor( + wireMockServer.register( get(urlEqualTo("/repos/$orgName/$repoName/issues/$issueId")) .willReturn( aResponse().withBody( @@ -597,7 +597,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { repoName: String, issueId: Int, ) { - wireMockServer.stubFor( + wireMockServer.register( post(urlEqualTo("/repos/$orgName/$repoName/issues/$issueId/comments")) .willReturn( aResponse().withBody( @@ -956,7 +956,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { """.trimIndent() }.joinToString(",") - wireMockServer.stubFor( + wireMockServer.register( get(urlEqualTo("/repos/$orgName/$repoName/pulls?state=open")) .willReturn( aResponse().withBody("[$responseBody]"), @@ -997,7 +997,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { """.trimIndent() } - wireMockServer.stubFor( + wireMockServer.register( get(urlEqualTo("/repos/$orgName/$repoName/issues/$issueId/comments")) .willReturn( aResponse().withBody("""[${responseBodies.joinToString(",")}]"""), @@ -1036,7 +1036,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { } """.trimIndent() - wireMockServer.stubFor( + wireMockServer.register( get(urlEqualTo("/repos/$orgName/$repoName/issues/comments/$commentId")) .willReturn( aResponse().withBody(responseBody), @@ -1074,7 +1074,7 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { } """.trimIndent() - wireMockServer.stubFor( + wireMockServer.register( patch(urlEqualTo("/repos/$orgName/$repoName/issues/comments/$commentId")) .willReturn( aResponse().withBody(responseBody), @@ -1086,15 +1086,15 @@ class GitHubWireMockStubber(private val wireMockServer: WireMockServer) { orgName: String, repoName: String, issueId: Int, - ) = wireMockServer.findRequestsMatching( - postRequestedFor(urlEqualTo("/repos/$orgName/$repoName/issues/$issueId/comments")).build(), - ).requests.map { it.bodyAsString } + ) = wireMockServer.find( + postRequestedFor(urlEqualTo("/repos/$orgName/$repoName/issues/$issueId/comments")), + ).map { it.bodyAsString } fun findUpdateCommentRequestBodies( orgName: String, repoName: String, commentId: Int, - ) = wireMockServer.findRequestsMatching( - patchRequestedFor(urlEqualTo("/repos/$orgName/$repoName/issues/comments/$commentId")).build(), - ).requests.map { it.bodyAsString } + ) = wireMockServer.find( + patchRequestedFor(urlEqualTo("/repos/$orgName/$repoName/issues/comments/$commentId")), + ).map { it.bodyAsString } } diff --git a/server/server-app/src/test/kotlin/projektor/incomingresults/SaveGroupedResultsWithMetadataPullRequestCommentApplicationTest.kt b/server/server-app/src/test/kotlin/projektor/incomingresults/SaveGroupedResultsWithMetadataPullRequestCommentApplicationTest.kt index 67df07dad..1e3de80d4 100644 --- a/server/server-app/src/test/kotlin/projektor/incomingresults/SaveGroupedResultsWithMetadataPullRequestCommentApplicationTest.kt +++ b/server/server-app/src/test/kotlin/projektor/incomingresults/SaveGroupedResultsWithMetadataPullRequestCommentApplicationTest.kt @@ -1,6 +1,7 @@ package projektor.incomingresults import com.github.tomakehurst.wiremock.WireMockServer +import com.github.tomakehurst.wiremock.client.WireMock import com.github.tomakehurst.wiremock.core.WireMockConfiguration import io.ktor.http.HttpHeaders import io.ktor.http.HttpMethod @@ -95,7 +96,7 @@ class SaveGroupedResultsWithMetadataPullRequestCommentApplicationTest : Applicat companion object { private val wireMockServer = WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()) - private val gitHubWireMockStubber = GitHubWireMockStubber(wireMockServer) + private val gitHubWireMockStubber = GitHubWireMockStubber(WireMock(wireMockServer)) @BeforeAll @JvmStatic diff --git a/server/server-app/src/test/kotlin/projektor/notification/github/GitHubPullRequestCommentApplicationTest.kt b/server/server-app/src/test/kotlin/projektor/notification/github/GitHubPullRequestCommentApplicationTest.kt index bca935756..379626af7 100644 --- a/server/server-app/src/test/kotlin/projektor/notification/github/GitHubPullRequestCommentApplicationTest.kt +++ b/server/server-app/src/test/kotlin/projektor/notification/github/GitHubPullRequestCommentApplicationTest.kt @@ -1,6 +1,7 @@ package projektor.notification.github import com.github.tomakehurst.wiremock.WireMockServer +import com.github.tomakehurst.wiremock.client.WireMock import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig import io.ktor.http.HttpHeaders import io.ktor.http.HttpMethod @@ -27,7 +28,7 @@ import strikt.assertions.hasSize class GitHubPullRequestCommentApplicationTest : ApplicationTestCase() { private val wireMockServer = WireMockServer(wireMockConfig().dynamicPort()) - private val gitHubWireMockStubber = GitHubWireMockStubber(wireMockServer) + private val gitHubWireMockStubber = GitHubWireMockStubber(WireMock(wireMockServer)) @BeforeEach fun startWireMock() {