Skip to content

Commit 0a0c013

Browse files
authored
test(abg): refactor assertion on the generated binding (#1592)
Part of #1585. This way these assertions will hold true if we add generation of untyped binding.
1 parent c55b6c2 commit 0a0c013

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

  • action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import io.kotest.assertions.fail
55
import io.kotest.matchers.shouldBe
66
import java.nio.file.Paths
77

8-
fun ActionBinding.shouldMatchFile(path: String) {
8+
fun List<ActionBinding>.shouldContainAndMatchFile(path: String) {
9+
val binding =
10+
this
11+
.firstOrNull { it.filePath.endsWith(path) }
12+
?: error("Binding with path ending with $path not found!")
913
val file =
1014
Paths
1115
.get("src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/$path")
@@ -15,9 +19,9 @@ fun ActionBinding.shouldMatchFile(path: String) {
1519
file.canRead() -> file.readText().removeWindowsNewLines()
1620
else -> ""
1721
}
18-
val actualContent = kotlinCode.removeWindowsNewLines()
22+
val actualContent = binding.kotlinCode.removeWindowsNewLines()
1923

20-
filePath shouldBe "kotlin/io/github/typesafegithub/workflows/actions/johnsmith/$path"
24+
binding.filePath shouldBe "kotlin/io/github/typesafegithub/workflows/actions/johnsmith/$path"
2125

2226
if (System.getenv("GITHUB_ACTIONS") == "true") {
2327
actualContent shouldBe expectedContent

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.TypingAc
66
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Input
77
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Metadata
88
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Output
9-
import io.github.typesafegithub.workflows.actionbindinggenerator.shouldMatchFile
9+
import io.github.typesafegithub.workflows.actionbindinggenerator.shouldContainAndMatchFile
1010
import io.github.typesafegithub.workflows.actionbindinggenerator.typing.BooleanTyping
1111
import io.github.typesafegithub.workflows.actionbindinggenerator.typing.EnumTyping
1212
import io.github.typesafegithub.workflows.actionbindinggenerator.typing.FloatTyping
@@ -15,7 +15,6 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.typing.IntegerW
1515
import io.github.typesafegithub.workflows.actionbindinggenerator.typing.ListOfTypings
1616
import io.github.typesafegithub.workflows.actionbindinggenerator.typing.StringTyping
1717
import io.kotest.core.spec.style.FunSpec
18-
import io.kotest.matchers.collections.shouldHaveSize
1918

2019
class GenerationTest :
2120
FunSpec({
@@ -143,8 +142,7 @@ class GenerationTest :
143142
val binding = coords.generateBinding(metadataRevision = NewestForVersion, metadata = actionManifest)
144143

145144
// then
146-
binding shouldHaveSize 1
147-
binding.first().shouldMatchFile("SimpleActionWithRequiredStringInputs.kt")
145+
binding.shouldContainAndMatchFile("SimpleActionWithRequiredStringInputs.kt")
148146
}
149147

150148
test("action with various combinations of input parameters describing being required or optional") {
@@ -189,8 +187,7 @@ class GenerationTest :
189187
val binding = coords.generateBinding(metadataRevision = NewestForVersion, metadata = actionManifest)
190188

191189
// then
192-
binding shouldHaveSize 1
193-
binding.first().shouldMatchFile("ActionWithSomeOptionalInputs.kt")
190+
binding.shouldContainAndMatchFile("ActionWithSomeOptionalInputs.kt")
194191
}
195192

196193
test("action with all types of inputs") {
@@ -210,8 +207,7 @@ class GenerationTest :
210207
)
211208

212209
// then
213-
binding shouldHaveSize 1
214-
binding.first().shouldMatchFile("ActionWithAllTypesOfInputs.kt")
210+
binding.shouldContainAndMatchFile("ActionWithAllTypesOfInputs.kt")
215211
}
216212

217213
test("action with outputs") {
@@ -241,8 +237,7 @@ class GenerationTest :
241237
val binding = coords.generateBinding(metadataRevision = NewestForVersion, metadata = actionManifest)
242238

243239
// then
244-
binding shouldHaveSize 1
245-
binding.first().shouldMatchFile("ActionWithOutputs.kt")
240+
binding.shouldContainAndMatchFile("ActionWithOutputs.kt")
246241
}
247242

248243
test("action with no inputs") {
@@ -261,8 +256,7 @@ class GenerationTest :
261256
val binding = coords.generateBinding(metadataRevision = NewestForVersion, metadata = actionManifest)
262257

263258
// then
264-
binding shouldHaveSize 1
265-
binding.first().shouldMatchFile("ActionWithNoInputs.kt")
259+
binding.shouldContainAndMatchFile("ActionWithNoInputs.kt")
266260
}
267261

268262
test("action with deprecated input resolving to the same Kotlin field name") {
@@ -295,8 +289,7 @@ class GenerationTest :
295289
val binding = coords.generateBinding(metadataRevision = NewestForVersion, metadata = actionManifest)
296290

297291
// then
298-
binding shouldHaveSize 1
299-
binding.first().shouldMatchFile("ActionWithDeprecatedInputAndNameClash.kt")
292+
binding.shouldContainAndMatchFile("ActionWithDeprecatedInputAndNameClash.kt")
300293
}
301294

302295
test("action with inputs sharing type") {
@@ -343,8 +336,7 @@ class GenerationTest :
343336
)
344337

345338
// then
346-
binding shouldHaveSize 1
347-
binding.first().shouldMatchFile("ActionWithInputsSharingType.kt")
339+
binding.shouldContainAndMatchFile("ActionWithInputsSharingType.kt")
348340
}
349341

350342
test("action with input descriptions with fancy characters") {
@@ -371,7 +363,6 @@ class GenerationTest :
371363
val binding = coords.generateBinding(metadataRevision = NewestForVersion, metadata = actionManifest)
372364

373365
// then
374-
binding shouldHaveSize 1
375-
binding.first().shouldMatchFile("ActionWithFancyCharsInDocs.kt")
366+
binding.shouldContainAndMatchFile("ActionWithFancyCharsInDocs.kt")
376367
}
377368
})

0 commit comments

Comments
 (0)