Skip to content

Commit c4fa425

Browse files
authored
test(abg): add tests for order of using typings from various sources (#1201)
Part of #1073. I'm going to introduce an important change here, so let's first ensure there's proper test coverage.
1 parent cee1b5a commit c4fa425

File tree

1 file changed

+120
-1
lines changed
  • action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator

1 file changed

+120
-1
lines changed

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TypesProvidingTest.kt

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package io.github.typesafegithub.workflows.actionbindinggenerator
22

33
import io.kotest.core.spec.style.FunSpec
44
import io.kotest.matchers.shouldBe
5+
import java.io.IOException
6+
import java.net.URI
57

68
class TypesProvidingTest : FunSpec({
7-
test("valid typing provided by action") {
9+
test("parses all allowed elements of valid typing") {
810
// Given
911
val actionTypesYml =
1012
"""
@@ -59,4 +61,121 @@ class TypesProvidingTest : FunSpec({
5961
"permissions" to EnumTyping("Permissions", listOf("user", "admin", "guest")),
6062
)
6163
}
64+
65+
context("order of using typings from various sources") {
66+
val hostedByActionYml = "inputs:\n hosted-by-action-yml:\n type: string"
67+
val hostedByActionYaml = "inputs:\n hosted-by-action-yaml:\n type: string"
68+
val storedInTypingCatalog = "inputs:\n stored-in-typing-catalog:\n type: string"
69+
70+
test("only hosted by the action (.yml)") {
71+
// Given
72+
val fetchUri: (URI) -> String = {
73+
when (it) {
74+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yml") -> hostedByActionYml
75+
else -> throw IOException()
76+
}
77+
}
78+
val actionCoord = ActionCoords("some-owner", "some-name", "v3")
79+
80+
// When
81+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
82+
83+
// Then
84+
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
85+
}
86+
87+
test("only hosted by the action (.yaml)") {
88+
// Given
89+
val fetchUri: (URI) -> String = {
90+
when (it) {
91+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yaml") -> hostedByActionYaml
92+
else -> throw IOException()
93+
}
94+
}
95+
val actionCoord = ActionCoords("some-owner", "some-name", "v3")
96+
97+
// When
98+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
99+
100+
// Then
101+
types shouldBe Pair(mapOf("hosted-by-action-yaml" to StringTyping), TypingActualSource.ACTION)
102+
}
103+
104+
test("only hosted by the action, both extensions") {
105+
// Given
106+
val fetchUri: (URI) -> String = {
107+
when (it) {
108+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yml") -> hostedByActionYml
109+
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yaml") -> hostedByActionYaml
110+
else -> throw IOException()
111+
}
112+
}
113+
val actionCoord = ActionCoords("some-owner", "some-name", "v3")
114+
115+
// When
116+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
117+
118+
// Then
119+
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
120+
}
121+
122+
test("only stored in typing catalog") {
123+
// Given
124+
val fetchUri: (URI) -> String = {
125+
when (it) {
126+
URI(
127+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
128+
"main/typings/some-owner/some-name/v3//action-types.yml",
129+
),
130+
-> storedInTypingCatalog
131+
else -> throw IOException()
132+
}
133+
}
134+
val actionCoord = ActionCoords("some-owner", "some-name", "v3")
135+
136+
// When
137+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
138+
139+
// Then
140+
types shouldBe Pair(mapOf("stored-in-typing-catalog" to StringTyping), TypingActualSource.TYPING_CATALOG)
141+
}
142+
143+
test("hosted by action and stored in typing catalog") {
144+
// Given
145+
val fetchUri: (URI) -> String = {
146+
when (it) {
147+
URI(
148+
"https://raw.githubusercontent.com/some-owner/some-name/" +
149+
"some-hash//action-types.yml",
150+
),
151+
-> hostedByActionYml
152+
URI(
153+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
154+
"main/typings/some-owner/some-name/v3//action-types.yml",
155+
),
156+
-> storedInTypingCatalog
157+
else -> throw IOException()
158+
}
159+
}
160+
val actionCoord = ActionCoords("some-owner", "some-name", "v3")
161+
162+
// When
163+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
164+
165+
// Then
166+
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
167+
}
168+
169+
test("no typings at all") {
170+
// Given
171+
val fetchUri: (URI) -> String = { throw IOException() }
172+
val actionCoord = ActionCoords("some-owner", "some-name", "v3")
173+
174+
// When
175+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), fetchUri = fetchUri)
176+
177+
// Then
178+
types shouldBe Pair(emptyMap(), null)
179+
}
180+
}
62181
})

0 commit comments

Comments
 (0)