-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ManifestsToReportTest.kt
205 lines (176 loc) · 5.78 KB
/
ManifestsToReportTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package it.krzeminski.githubactionstyping.validation
import io.kotest.assertions.assertSoftly
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import it.krzeminski.githubactionstyping.manifestsToReport
class ManifestsToReportTest : FunSpec({
test("success case") {
// when
val manifest = """
name: GitHub Actions Typing
description: Bring type-safety to your GitHub actions' API!
author: Piotr Krzemiński
inputs:
verbose:
description: 'Set to true to display debug information helpful when troubleshooting issues with this action.'
required: false
default: 'false'
someEnum:
description: 'Testing enum'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
""".trimIndent()
val typesManifest = """
inputs:
verbose:
type: boolean
someEnum:
type: enum
allowed-values:
- foo
- bar
""".trimIndent()
// when
val (isValid, report) = manifestsToReport(manifest, typesManifest)
// then
assertSoftly {
isValid shouldBe true
report shouldBe """
Overall result:
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
Inputs:
• verbose:
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
• someEnum:
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
Outputs:
None.
""".trimIndent()
}
}
test("success case with anchor and alias") {
// when
val manifest = """
name: GitHub Actions Typing
description: Bring type-safety to your GitHub actions' API!
author: Piotr Krzemiński
inputs:
verbose:
description: 'Set to true to display debug information helpful when troubleshooting issues with this action.'
required: false
default: 'false'
someEnum:
description: 'Testing enum'
required: false
someEnum2:
description: 'Testing enum'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
""".trimIndent()
val typesManifest = """
inputs:
verbose:
type: boolean
someEnum:
type: enum
allowed-values: &enum-allowed-values
- foo
- bar
someEnum2:
type: enum
allowed-values: *enum-allowed-values
""".trimIndent()
// when
val (isValid, report) = manifestsToReport(manifest, typesManifest)
// then
assertSoftly {
isValid shouldBe true
report shouldBe """
Overall result:
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
Inputs:
• verbose:
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
• someEnum:
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
• someEnum2:
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
Outputs:
None.
""".trimIndent()
}
}
test("blank types YAML") {
// when
val manifest = """
name: GitHub Actions Typing
description: Bring type-safety to your GitHub actions' API!
author: Piotr Krzemiński
runs:
using: 'docker'
image: 'Dockerfile'
""".trimIndent()
val typesManifest = " "
// when
val (isValid, report) = manifestsToReport(manifest, typesManifest)
// then
assertSoftly {
isValid shouldBe true
report shouldBe """
Overall result:
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
Inputs:
None.
Outputs:
None.
""".trimIndent()
}
}
test("enum: missing allowed values") {
// when
val manifest = """
name: GitHub Actions Typing
description: Bring type-safety to your GitHub actions' API!
author: Piotr Krzemiński
inputs:
verbose:
description: 'Set to true to display debug information helpful when troubleshooting issues with this action.'
required: false
default: 'false'
someEnum:
description: 'Testing enum'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
""".trimIndent()
val typesManifest = """
inputs:
verbose:
type: boolean
someEnum:
type: enum
""".trimIndent()
// when
val (isValid, report) = manifestsToReport(manifest, typesManifest)
// then
assertSoftly {
isValid shouldBe false
report shouldBe """
Overall result:
${'\u001b'}[31m❌ INVALID: Some typing is invalid.${'\u001b'}[0m
Inputs:
• verbose:
${'\u001b'}[32m✔ VALID${'\u001b'}[0m
• someEnum:
${'\u001b'}[31m❌ INVALID: Allowed values must be specified.${'\u001b'}[0m
Outputs:
None.
""".trimIndent()
}
}
})