Skip to content

Commit

Permalink
Test gitea webhooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
CamaradeRoman committed May 31, 2024
1 parent 44c515c commit 38bdb9a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions ft/docker/gitea/application-gitea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vcs-facade:
last-release: 321d4908aef10bafa1488f9b053270acc29f3d78
expected-commits: 9320183f5d5f5868fdb82b36e3abd6f9d1424114,00cc61dd4c3eca64d12e6beceff1a40a436962f5
index:
webhook-secret: b59dd966-2445-4c84-b631-49502427477e
scan:
delay: 5000
gitlab:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,90 @@
package org.octopusden.octopus.vcsfacade

import java.net.HttpURLConnection
import java.net.URI
import java.util.Base64
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.octopusden.octopus.infrastructure.common.test.dto.NewChangeSet
import org.octopusden.octopus.infrastructure.gitea.test.GiteaTestClient
import org.octopusden.octopus.vcsfacade.client.common.dto.CreatePullRequest

@EnabledIfSystemProperty(named = "test.profile", matches = "gitea")
class VcsFacadeFunctionalTestGitea : BaseVcsFacadeFunctionalTest(
TestService.Gitea(GITEA_HOST, GITEA_EXTERNAL_HOST, true),
GiteaTestClient("http://$GITEA_HOST", GITEA_USER, GITEA_PASSWORD, GITEA_EXTERNAL_HOST)
) {
@BeforeAll
fun beforeAllVcsFacadeUnitTestGitea() {
fun beforeAllVcsFacadeFunctionalTestGitea() {
val url = URI("http://$GITEA_HOST/api/v1/repos/$GROUP/$REPOSITORY_2/hooks").toURL()
with(url.openConnection() as HttpURLConnection) {
setRequestMethod("POST")
setRequestProperty(
"Authorization",
"Basic " + Base64.getEncoder().encodeToString("$GITEA_USER:$GITEA_PASSWORD".toByteArray())
)
setRequestProperty("Content-Type", "application/json")
setRequestProperty("Accept", "application/json")
setDoOutput(true)
outputStream.use {
it.write(WEBHOOK_CREATION_REQUEST.toByteArray())
}
if (getResponseCode() / 100 != 2) {
throw RuntimeException("Unable to create webhook for '$GROUP:$REPOSITORY_2'")
}
}
(testService as TestService.Gitea).scan(GROUP, REPOSITORY_2)
}

@Test
fun webhooksTest() {
var success = false
testClient.commit(
NewChangeSet("Commit (ISSUE-10)", testService.sshUrl(GROUP, REPOSITORY_2), "ISSUE-10"),
"master"
)
for (i in 1..5) {
Thread.sleep(1000L * i)
success = with(findByIssueKey("ISSUE-10")) {
branches.size == 1 && commits.size == 1 && pullRequests.size == 0
}
if (success) break
}
if (!success) throw RuntimeException("Commit and branch for ISSUE-10 have not been registered")
createPullRequest(
testService.sshUrl(GROUP, REPOSITORY_2),
CreatePullRequest("ISSUE-10", "master", "Webhook test PR", "Description ISSUE-10")
)
for (i in 1..5) {
Thread.sleep(1000L * i)
success = with(findByIssueKey("ISSUE-10")) {
branches.size == 1 && commits.size == 1 && pullRequests.size == 1
}
if (success) break
}
if (!success) throw RuntimeException("Pull request for ISSUE-10 has not been registered")
}

companion object {
//<editor-fold defaultstate="collapsed" desc="webhook creation request">
const val WEBHOOK_CREATION_REQUEST = """{
"type": "gitea",
"branch_filter": "*",
"config": {
"content_type": "json",
"url": "http://vcs-facade:8080/rest/api/1/indexer/gitea/webhook",
"secret": "b59dd966-2445-4c84-b631-49502427477e"
},
"events": [
"create",
"delete",
"push",
"pull_request"
],
"authorization_header": "",
"active": true
}"""
//</editor-fold>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.octopusden.octopus.vcsfacade.client.common.exception.NotFoundExceptio
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
abstract class BaseVcsFacadeTest(
protected val testService: TestService,
private val testClient: TestClient
protected val testClient: TestClient
) {
@BeforeAll
fun beforeAllBaseVcsFacadeTest() {
Expand Down

0 comments on commit 38bdb9a

Please sign in to comment.