Skip to content

Commit b712d98

Browse files
committed
test(library): compare runner labels supported by GitHub with supported by library
1 parent f0cdf77 commit b712d98

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/domain/GithubHostedRunnerLabelsListing.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import io.ktor.client.statement.bodyAsText
77
/**
88
* Lists values allowed to be set in "runs-on" for a job, for GitHub-hosted runners.
99
*/
10-
suspend fun listRunnerLabels(): List<String> {
10+
suspend fun listRunnerLabels(): Set<String> {
1111
val html = HttpClient().get(GITHUB_RUNNER_LABELS_DOCS_URL).bodyAsText()
1212
return parse(html)
1313
}
1414

1515
private const val GITHUB_RUNNER_LABELS_DOCS_URL: String =
1616
"https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions"
1717

18-
private fun parse(html: String): List<String> =
18+
private fun parse(html: String): Set<String> =
1919
RUNNER_LABEL_REGEX
2020
.findAll(html)
2121
.map { it.groupValues[1] }
22-
.toList()
22+
.toSet()
2323

2424
private val RUNNER_LABEL_REGEX =
2525
Regex(

github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/domain/RunnerTypeTest.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
package io.github.typesafegithub.workflows.domain
22

3+
import io.kotest.assertions.assertSoftly
34
import io.kotest.assertions.throwables.shouldThrow
5+
import io.kotest.assertions.withClue
46
import io.kotest.core.spec.style.FunSpec
7+
import io.kotest.matchers.shouldBe
58

69
class RunnerTypeTest :
710
FunSpec({
11+
test("all supported runner labels should correspond to lib's classes") {
12+
val fromLib =
13+
RunnerType.GitHubHosted::class
14+
.sealedSubclasses
15+
.mapNotNull { it.objectInstance?.value }
16+
.toSet()
17+
val fromDocs = listRunnerLabels().toSet()
18+
19+
assertSoftly {
20+
withClue("no obsolete labels are in the lib") {
21+
fromLib - fromDocs shouldBe emptySet<String>()
22+
}
23+
24+
withClue("no missing labels are in the lib") {
25+
fromDocs - fromLib shouldBe emptySet<String>()
26+
}
27+
}
28+
}
29+
830
context("Labelled") {
931
test("should throw on invalid arguments") {
1032
shouldThrow<IllegalArgumentException> {

0 commit comments

Comments
 (0)