Skip to content

Commit d111415

Browse files
authored
test: add regresison tests for requesting non-major version and fetching typings from catalog (#2257)
Part of #2253. These tests show that when a non-major version is requested, we first try to fetch typings from the catalog for its corresponding major version.
1 parent 53d6a96 commit d111415

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

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

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ class TypesProvidingTest :
195195
stored-in-typing-catalog-for-older-version:
196196
type: string
197197
""".trimIndent()
198+
val storedInTypingCatalogForMajorVersion =
199+
"""
200+
inputs:
201+
stored-in-typing-catalog-for-major-version:
202+
type: string
203+
""".trimIndent()
198204

199205
test("only hosted by the action (.yml)") {
200206
// Given
@@ -636,6 +642,49 @@ class TypesProvidingTest :
636642
)
637643
}
638644

645+
test("only stored in typing catalog for same major version using non-major version") {
646+
// Given
647+
val mockClient =
648+
HttpClient(
649+
MockEngine { request ->
650+
if (request.url.toString() ==
651+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
652+
"main/typings/some-owner/some-name/metadata.yml"
653+
) {
654+
respond(metadata)
655+
} else if (request.url.toString() ==
656+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
657+
"main/typings/some-owner/some-name/v4/action-types.yml"
658+
) {
659+
respond(storedInTypingCatalogForMajorVersion)
660+
} else if (request.url.toString() ==
661+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
662+
"main/typings/some-owner/some-name/v3/action-types.yml"
663+
) {
664+
respond(storedInTypingCatalogForOlderVersion)
665+
} else {
666+
respond("Not found", status = HttpStatusCode.NotFound)
667+
}
668+
},
669+
)
670+
val actionCoord = ActionCoords("Some-owner", "Some-name", "v4.1.2")
671+
672+
// When
673+
val types =
674+
actionCoord.provideTypes(
675+
metadataRevision = CommitHash("some-hash"),
676+
httpClient = mockClient,
677+
)
678+
679+
// Then
680+
types shouldBe
681+
ActionTypings(
682+
inputTypings = mapOf("stored-in-typing-catalog-for-major-version" to StringTyping),
683+
source = TypingActualSource.TYPING_CATALOG,
684+
fromFallbackVersion = false,
685+
)
686+
}
687+
639688
test("only stored in typing catalog for older version using commit pinning") {
640689
// Given
641690
val mockClient =
@@ -792,6 +841,49 @@ class TypesProvidingTest :
792841
)
793842
}
794843

844+
test("only stored in typing catalog for same major version of subaction using non-major version") {
845+
// Given
846+
val mockClient =
847+
HttpClient(
848+
MockEngine { request ->
849+
if (request.url.toString() ==
850+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
851+
"main/typings/some-owner/some-name/metadata.yml"
852+
) {
853+
respond(metadata)
854+
} else if (request.url.toString() ==
855+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
856+
"main/typings/some-owner/some-name/v4/some-sub/action-types.yml"
857+
) {
858+
respond(storedInTypingCatalogForMajorVersion)
859+
} else if (request.url.toString() ==
860+
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
861+
"main/typings/some-owner/some-name/v3/some-sub/action-types.yml"
862+
) {
863+
respond(storedInTypingCatalogForOlderVersion)
864+
} else {
865+
respond("Not found", status = HttpStatusCode.NotFound)
866+
}
867+
},
868+
)
869+
val actionCoord = ActionCoords("some-owner", "some-name", "v4.1.2", FULL, path = "some-sub")
870+
871+
// When
872+
val types =
873+
actionCoord.provideTypes(
874+
metadataRevision = CommitHash("some-hash"),
875+
httpClient = mockClient,
876+
)
877+
878+
// Then
879+
types shouldBe
880+
ActionTypings(
881+
inputTypings = mapOf("stored-in-typing-catalog-for-major-version" to StringTyping),
882+
source = TypingActualSource.TYPING_CATALOG,
883+
fromFallbackVersion = false,
884+
)
885+
}
886+
795887
test("only stored in typing catalog for older version of subaction using commit pinning") {
796888
// Given
797889
val mockClient =

0 commit comments

Comments
 (0)