Skip to content

Commit c3fc6b9

Browse files
committed
test(library): add test for reading contexts without optional fields
1 parent 2013c93 commit c3fc6b9

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/yaml/ContextMappingTest.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ContextMappingTest :
1010
FunSpec({
1111
test("successfully load all supported contexts with all supported fields") {
1212
// Given
13-
val testGithubContextJson = javaClass.getResource("/contexts/github.json")!!.readText()
13+
val testGithubContextJson = javaClass.getResource("/contexts/github-all-fields.json")!!.readText()
1414

1515
// When
1616
val contexts =
@@ -36,4 +36,29 @@ class ContextMappingTest :
3636
),
3737
)
3838
}
39+
40+
test("successfully load all supported contexts with only required fields") {
41+
// Given
42+
val testGithubContextJson = javaClass.getResource("/contexts/github-required-fields.json")!!.readText()
43+
44+
// When
45+
val contexts =
46+
loadContextsFromEnvVars(
47+
getenv = mapOf(
48+
"GHWKT_GITHUB_CONTEXT_JSON" to testGithubContextJson,
49+
)::get,
50+
)
51+
52+
// Then
53+
contexts shouldBe
54+
Contexts(
55+
github =
56+
GithubContext(
57+
repository = "some-owner/some-repo",
58+
sha = "db76dd0f1149901e1cdf60ec98d568b32fa7eb71",
59+
event = GithubContextEvent(),
60+
event_name = "push",
61+
),
62+
)
63+
}
3964
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"repository": "some-owner/some-repo",
3+
"sha": "db76dd0f1149901e1cdf60ec98d568b32fa7eb71",
4+
"event": {},
5+
"event_name": "push"
6+
}

0 commit comments

Comments
 (0)