Skip to content

Commit 947707c

Browse files
committed
test(server): add unit tests for extractActionCoords function in ActionCoordsTest
1 parent 1e85963 commit 947707c

File tree

1 file changed

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

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 : FunSpec(
13+
{
14+
test("extractActionCoords parses owner/name with version and no path, FULL by default") {
15+
val parameters = createParameters(owner = "o", name = "act", version = "v1")
16+
17+
parameters.extractActionCoords(true) shouldBe ActionCoords(
18+
owner = "o",
19+
name = "act",
20+
version = "v1",
21+
significantVersion = FULL,
22+
path = null
23+
)
24+
}
25+
26+
test("extractActionCoords parses owner/name with path and significant version suffix") {
27+
val parameters = createParameters(owner = "o", name = "act__p1__p2___major", version = "v9")
28+
29+
parameters.extractActionCoords(true) shouldBe ActionCoords(
30+
owner = "o",
31+
name = "act",
32+
version = "v9",
33+
significantVersion = MAJOR,
34+
path = "p1/p2",
35+
)
36+
}
37+
38+
test("when extractVersion=false, version field is set to 'irrelevant'") {
39+
val parameters = createParameters(owner = "o", name = "act___minor")
40+
41+
parameters.extractActionCoords(false) shouldBe ActionCoords(
42+
owner = "o",
43+
name = "act",
44+
version = "irrelevant",
45+
significantVersion = MINOR,
46+
path = null,
47+
)
48+
}
49+
50+
test("unknown significant version part falls back to FULL") {
51+
val parameters = createParameters(owner = "o", name = "act___weird")
52+
53+
parameters.extractActionCoords(false) shouldBe ActionCoords(
54+
owner = "o",
55+
name = "act",
56+
version = "irrelevant",
57+
significantVersion = FULL,
58+
path = null,
59+
)
60+
}
61+
62+
test("handles name with underscores/hyphens and path segments") {
63+
val parameters = createParameters(owner = "o", name = "my_action-name__dir_one__dir-two___minor", version = "v2")
64+
65+
parameters.extractActionCoords(true) shouldBe ActionCoords(
66+
owner = "o",
67+
name = "my_action-name",
68+
version = "v2",
69+
significantVersion = MINOR,
70+
path = "dir_one/dir-two",
71+
)
72+
}
73+
74+
test("empty path part yields no path") {
75+
val parameters = createParameters(owner = "o", name = "act__\u200B___major", version = "v3") // zero-width space as noise
76+
77+
parameters.extractActionCoords(true) shouldBe ActionCoords(
78+
owner = "o",
79+
name = "act",
80+
version = "v3",
81+
significantVersion = MAJOR,
82+
path = null,
83+
)
84+
}
85+
},
86+
)
87+
88+
private fun createParameters(owner: String, name: String, version: String? = null): Parameters =
89+
ParametersBuilder().apply {
90+
append("owner", owner)
91+
append("name", name)
92+
version?.let { append("version", it) }
93+
}.build()

0 commit comments

Comments
 (0)