-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't show the repo coverage section if the repo doesn't have any cov…
…erage data to display (#1210) * Don't show the repo coverage section if the repo doesn't have any coverage data to display * Add coverage-exists call for repo
- Loading branch information
Showing
16 changed files
with
505 additions
and
112 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
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
181 changes: 181 additions & 0 deletions
181
.../src/test/kotlin/projektor/repository/coverage/RepositoryCoverageExistsApplicationTest.kt
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,181 @@ | ||
package projektor.repository.coverage | ||
|
||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import io.ktor.http.* | ||
import io.ktor.server.testing.* | ||
import org.apache.commons.lang3.RandomStringUtils | ||
import org.junit.jupiter.api.Test | ||
import projektor.ApplicationTestCase | ||
import projektor.incomingresults.randomPublicId | ||
import projektor.server.api.coverage.CoverageExists | ||
import projektor.server.example.coverage.JacocoXmlLoader | ||
import strikt.api.expectThat | ||
import strikt.assertions.isEqualTo | ||
import strikt.assertions.isFalse | ||
import strikt.assertions.isTrue | ||
import kotlin.test.assertNotNull | ||
|
||
class RepositoryCoverageExistsApplicationTest : ApplicationTestCase() { | ||
@Test | ||
fun `when repo has coverage should exist`() { | ||
val orgName = RandomStringUtils.randomAlphabetic(12) | ||
val repoName = "$orgName/repo" | ||
|
||
val runInRepoPublicId = randomPublicId() | ||
val runInDifferentProjectPublicId = randomPublicId() | ||
val runInDifferentRepoPublicId = randomPublicId() | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/repo/$repoName/coverage/exists") { | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInRepoPublicId, | ||
coverageText = JacocoXmlLoader().serverAppReduced(), | ||
repoName = repoName, | ||
branchName = "main" | ||
) | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInDifferentProjectPublicId, | ||
coverageText = JacocoXmlLoader().junitResultsParser(), | ||
repoName = repoName, | ||
branchName = "main", | ||
projectName = "other-project" | ||
) | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInDifferentRepoPublicId, | ||
coverageText = JacocoXmlLoader().junitResultsParser(), | ||
repoName = "other/repo", | ||
branchName = "main" | ||
) | ||
}.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
val responseBody = response.content | ||
assertNotNull(responseBody) | ||
|
||
val coverageExists: CoverageExists = objectMapper.readValue(responseBody) | ||
expectThat(coverageExists.exists).isTrue() | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `when coverage exists only in project should not exist`() { | ||
val orgName = RandomStringUtils.randomAlphabetic(12) | ||
val repoName = "$orgName/repo" | ||
|
||
val runInDifferentProjectPublicId = randomPublicId() | ||
val runInDifferentRepoPublicId = randomPublicId() | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/repo/$repoName/coverage/exists") { | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInDifferentProjectPublicId, | ||
coverageText = JacocoXmlLoader().junitResultsParser(), | ||
repoName = repoName, | ||
branchName = "main", | ||
projectName = "other-project" | ||
) | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInDifferentRepoPublicId, | ||
coverageText = JacocoXmlLoader().junitResultsParser(), | ||
repoName = "other/repo", | ||
branchName = "main" | ||
) | ||
}.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
val responseBody = response.content | ||
assertNotNull(responseBody) | ||
|
||
val coverageExists: CoverageExists = objectMapper.readValue(responseBody) | ||
expectThat(coverageExists.exists).isFalse() | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `when repo and project has coverage should exist`() { | ||
val orgName = RandomStringUtils.randomAlphabetic(12) | ||
val repoName = "$orgName/repo" | ||
|
||
val projectName = "myproject" | ||
|
||
val runInRepoPublicId = randomPublicId() | ||
val runInProjectPublicId = randomPublicId() | ||
val runInDifferentRepoPublicId = randomPublicId() | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/repo/$repoName/project/$projectName/coverage/exists") { | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInRepoPublicId, | ||
coverageText = JacocoXmlLoader().serverAppReduced(), | ||
repoName = repoName, | ||
branchName = "main" | ||
) | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInProjectPublicId, | ||
coverageText = JacocoXmlLoader().junitResultsParser(), | ||
repoName = repoName, | ||
branchName = "main", | ||
projectName = projectName | ||
) | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInDifferentRepoPublicId, | ||
coverageText = JacocoXmlLoader().junitResultsParser(), | ||
repoName = "other/repo", | ||
branchName = "main" | ||
) | ||
}.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
val responseBody = response.content | ||
assertNotNull(responseBody) | ||
|
||
val coverageExists: CoverageExists = objectMapper.readValue(responseBody) | ||
expectThat(coverageExists.exists).isTrue() | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `when coverage only in null project should not exist`() { | ||
val orgName = RandomStringUtils.randomAlphabetic(12) | ||
val repoName = "$orgName/repo" | ||
|
||
val projectName = "myproject" | ||
|
||
val runInRepoPublicId = randomPublicId() | ||
val runInDifferentRepoPublicId = randomPublicId() | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/repo/$repoName/project/$projectName/coverage/exists") { | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInRepoPublicId, | ||
coverageText = JacocoXmlLoader().serverAppReduced(), | ||
repoName = repoName, | ||
branchName = "main" | ||
) | ||
|
||
testRunDBGenerator.createTestRunWithCoverageAndGitMetadata( | ||
publicId = runInDifferentRepoPublicId, | ||
coverageText = JacocoXmlLoader().junitResultsParser(), | ||
repoName = "other/repo", | ||
branchName = "main" | ||
) | ||
}.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
val responseBody = response.content | ||
assertNotNull(responseBody) | ||
|
||
val coverageExists: CoverageExists = objectMapper.readValue(responseBody) | ||
expectThat(coverageExists.exists).isFalse() | ||
} | ||
} | ||
} | ||
} |
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,3 @@ | ||
{ | ||
"exists": true | ||
} |
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.