Skip to content

Commit 2978812

Browse files
authored
test(server): add unit tests for extractActionCoords function in ActionCoordsTest (#2140)
1 parent 4f56e2c commit 2978812

File tree

1 file changed

+95
-0
lines changed
  • jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package io.github.typesafegithub.workflows.jitbindingserver
2+
3+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
4+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL
5+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MAJOR
6+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MINOR
7+
import io.kotest.core.spec.style.FunSpec
8+
import io.kotest.matchers.shouldBe
9+
import io.ktor.http.Parameters
10+
import io.ktor.http.ParametersBuilder
11+
12+
class ActionCoordsTest :
13+
FunSpec(
14+
{
15+
context("extractActionCoords") {
16+
test("parses owner/name with version and no path, FULL by default") {
17+
val parameters = createParameters(owner = "o", name = "act", version = "v1")
18+
19+
parameters.extractActionCoords(extractVersion = true) shouldBe
20+
ActionCoords(
21+
owner = "o",
22+
name = "act",
23+
version = "v1",
24+
significantVersion = FULL,
25+
path = null,
26+
)
27+
}
28+
29+
test("parses owner/name with path and significant version suffix") {
30+
val parameters = createParameters(owner = "o", name = "act__p1__p2___major", version = "v9")
31+
32+
parameters.extractActionCoords(extractVersion = true) shouldBe
33+
ActionCoords(
34+
owner = "o",
35+
name = "act",
36+
version = "v9",
37+
significantVersion = MAJOR,
38+
path = "p1/p2",
39+
)
40+
}
41+
42+
test("when extractVersion=false, version field is set to 'irrelevant'") {
43+
val parameters = createParameters(owner = "o", name = "act___minor")
44+
45+
parameters.extractActionCoords(extractVersion = false) shouldBe
46+
ActionCoords(
47+
owner = "o",
48+
name = "act",
49+
version = "irrelevant",
50+
significantVersion = MINOR,
51+
path = null,
52+
)
53+
}
54+
55+
test("unknown significant version part falls back to FULL") {
56+
val parameters = createParameters(owner = "o", name = "act___weird")
57+
58+
parameters.extractActionCoords(extractVersion = false) shouldBe
59+
ActionCoords(
60+
owner = "o",
61+
name = "act",
62+
version = "irrelevant",
63+
significantVersion = FULL,
64+
path = null,
65+
)
66+
}
67+
68+
test("handles name with underscores/hyphens and path segments") {
69+
val parameters =
70+
createParameters(owner = "o", name = "my_action-name__dir_one__dir-two___minor", version = "v2")
71+
72+
parameters.extractActionCoords(extractVersion = true) shouldBe
73+
ActionCoords(
74+
owner = "o",
75+
name = "my_action-name",
76+
version = "v2",
77+
significantVersion = MINOR,
78+
path = "dir_one/dir-two",
79+
)
80+
}
81+
}
82+
},
83+
)
84+
85+
private fun createParameters(
86+
owner: String,
87+
name: String,
88+
version: String? = null,
89+
): Parameters =
90+
ParametersBuilder()
91+
.apply {
92+
append("owner", owner)
93+
append("name", name)
94+
version?.let { append("version", it) }
95+
}.build()

0 commit comments

Comments
 (0)