Skip to content

Commit 27587f2

Browse files
Vampirekrzema12
andauthored
test: add some bad typings test cases (#289)
Co-authored-by: Piotr Krzemiński <[email protected]>
1 parent 4930875 commit 27587f2

25 files changed

+326
-8
lines changed

src/jvmTest/kotlin/it/krzeminski/githubactionstyping/LogicConsistencyTest.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package it.krzeminski.githubactionstyping
22

3+
import com.charleskorn.kaml.IncorrectTypeException
4+
import com.charleskorn.kaml.InvalidPropertyValueException
35
import io.kotest.assertions.assertSoftly
46
import io.kotest.assertions.withClue
57
import io.kotest.matchers.should
@@ -29,14 +31,23 @@ class LogicConsistencyTest : UseCaseTest() {
2931
.trimMargin("#")
3032
.trim()
3133

32-
val validationResult = parseTypesManifest(typesManifest).validate(typing.toPath().fileName)
33-
assertSoftly {
34-
validationResult.overallResult should beOfType<ItemValidationResult.Invalid>()
35-
validationResult
36-
.toPlaintextReport()
37-
.trim()
38-
.replace("\u001B", "\\x1B")
39-
.shouldBe(expectedValidationError)
34+
val parsedTypesManifest = runCatching {
35+
parseTypesManifest(typesManifest).validate(typing.toPath().fileName)
36+
}
37+
if (parsedTypesManifest.isFailure &&
38+
((parsedTypesManifest.exceptionOrNull() is InvalidPropertyValueException) || (parsedTypesManifest.exceptionOrNull() is IncorrectTypeException))
39+
) {
40+
parsedTypesManifest.exceptionOrNull()!!.message shouldBe expectedValidationError
41+
} else {
42+
val validationResult = parsedTypesManifest.getOrThrow()
43+
assertSoftly {
44+
validationResult.overallResult should beOfType<ItemValidationResult.Invalid>()
45+
validationResult
46+
.toPlaintextReport()
47+
.trim()
48+
.replace("\u001B", "\\x1B")
49+
.shouldBe(expectedValidationError)
50+
}
4051
}
4152
}
4253
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
granted-scopes:
5+
type: list
6+
separator: ','
7+
list-item:
8+
type: enum
9+
allowed-values: foo
10+
11+
# Expected validation error
12+
#
13+
#Value for 'inputs' is invalid: Value for 'granted-scopes' is invalid: Value for 'list-item' is invalid: Value for 'allowed-values' is invalid: Expected a list, but got a scalar value
14+
#
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
permissions:
5+
type: enum
6+
allowed-values: foo
7+
8+
# Expected validation error
9+
#
10+
#Value for 'inputs' is invalid: Value for 'permissions' is invalid: Value for 'allowed-values' is invalid: Expected a list, but got a scalar value
11+
#
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
list-of-integer:
5+
type: list
6+
separator: ','
7+
list-item:
8+
type: integer
9+
name: AllowedValues
10+
named-values: []
11+
12+
# Expected validation error
13+
#
14+
#Value for 'inputs' is invalid: Value for 'list-of-integer' is invalid: Value for 'list-item' is invalid: Value for 'named-values' is invalid: Expected a map, but got a list
15+
#
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
retries:
5+
type: integer
6+
name: AllowedValues
7+
named-values: []
8+
9+
# Expected validation error
10+
#
11+
#Value for 'inputs' is invalid: Value for 'retries' is invalid: Value for 'named-values' is invalid: Expected a map, but got a list
12+
#
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
input-files:
5+
type: list
6+
separator:
7+
list-item:
8+
type: string
9+
10+
# Expected validation error
11+
#
12+
#For action with manifest at 'inputs_list_with_null_separator.yml':
13+
#Result:
14+
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
15+
#
16+
#Inputs:
17+
#• input-files:
18+
# \x1B[31m❌ INVALID: Separator must be specified.\x1B[0m
19+
#
20+
#Outputs:
21+
#None.
22+
#
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
permissions:
5+
type: 0x0
6+
7+
# Expected validation error
8+
#
9+
#For action with manifest at 'inputs_with_non_string_type.yml':
10+
#Result:
11+
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
12+
#
13+
#Inputs:
14+
#• permissions:
15+
# \x1B[31m❌ INVALID: Unknown type: '0x0'.\x1B[0m
16+
#
17+
#Outputs:
18+
#None.
19+
#
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
permissions:
5+
type:
6+
7+
# Expected validation error
8+
#
9+
#For action with manifest at 'inputs_with_null_type.yml':
10+
#Result:
11+
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
12+
#
13+
#Inputs:
14+
#• permissions:
15+
# \x1B[31m❌ INVALID: Type must be specified. Use 'type' attribute.\x1B[0m
16+
#
17+
#Outputs:
18+
#None.
19+
#
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
granted-scopes:
5+
type: list
6+
separator: ','
7+
list-item:
8+
type: enum
9+
allowed-values: foo
10+
11+
# Expected validation error
12+
#
13+
#Value for 'outputs' is invalid: Value for 'granted-scopes' is invalid: Value for 'list-item' is invalid: Value for 'allowed-values' is invalid: Expected a list, but got a scalar value
14+
#
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
permissions:
5+
type: enum
6+
allowed-values: foo
7+
8+
# Expected validation error
9+
#
10+
#Value for 'outputs' is invalid: Value for 'permissions' is invalid: Value for 'allowed-values' is invalid: Expected a list, but got a scalar value
11+
#
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
list-of-integer:
5+
type: list
6+
separator: ','
7+
list-item:
8+
type: integer
9+
named-values: []
10+
11+
# Expected validation error
12+
#
13+
#Value for 'outputs' is invalid: Value for 'list-of-integer' is invalid: Value for 'list-item' is invalid: Value for 'named-values' is invalid: Expected a map, but got a list
14+
#
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
retries:
5+
type: integer
6+
named-values: []
7+
8+
# Expected validation error
9+
#
10+
#Value for 'outputs' is invalid: Value for 'retries' is invalid: Value for 'named-values' is invalid: Expected a map, but got a list
11+
#
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
input-files:
5+
type: list
6+
separator:
7+
list-item:
8+
type: string
9+
10+
# Expected validation error
11+
#
12+
#For action with manifest at 'outputs_list_with_null_separator.yml':
13+
#Result:
14+
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
15+
#
16+
#Inputs:
17+
#None.
18+
#
19+
#Outputs:
20+
#• input-files:
21+
# \x1B[31m❌ INVALID: Separator must be specified.\x1B[0m
22+
#
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
permissions:
5+
type: 0x0
6+
7+
# Expected validation error
8+
#
9+
#For action with manifest at 'outputs_with_non_string_type.yml':
10+
#Result:
11+
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
12+
#
13+
#Inputs:
14+
#None.
15+
#
16+
#Outputs:
17+
#• permissions:
18+
# \x1B[31m❌ INVALID: Unknown type: '0x0'.\x1B[0m
19+
#
20+
#
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
permissions:
5+
type:
6+
7+
# Expected validation error
8+
#
9+
#For action with manifest at 'outputs_with_null_type.yml':
10+
#Result:
11+
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
12+
#
13+
#Inputs:
14+
#None.
15+
#
16+
#Outputs:
17+
#• permissions:
18+
# \x1B[31m❌ INVALID: Type must be specified. Use 'type' attribute.\x1B[0m
19+
#
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
foo: bar
5+
6+
# Expected validation error
7+
#
8+
#Value for 'inputs' is invalid: Value for 'foo' is invalid: Expected an object, but got a scalar value
9+
#
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs: foo
4+
5+
# Expected validation error
6+
#
7+
#Value for 'inputs' is invalid: Expected a map, but got a scalar value
8+
#
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
foo: bar
5+
6+
# Expected validation error
7+
#
8+
#Value for 'outputs' is invalid: Value for 'foo' is invalid: Expected an object, but got a scalar value
9+
#
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs: foo
4+
5+
# Expected validation error
6+
#
7+
#Value for 'outputs' is invalid: Expected a map, but got a scalar value
8+
#
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
foo: []
5+
6+
# Expected validation error
7+
#
8+
#Value for 'inputs' is invalid: Value for 'foo' is invalid: Expected an object, but got a list
9+
#
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs: []
4+
5+
# Expected validation error
6+
#
7+
#Value for 'inputs' is invalid: Expected a map, but got a list
8+
#
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
foo: []
5+
6+
# Expected validation error
7+
#
8+
#Value for 'outputs' is invalid: Value for 'foo' is invalid: Expected an object, but got a list
9+
#
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs: []
4+
5+
# Expected validation error
6+
#
7+
#Value for 'outputs' is invalid: Expected a map, but got a list
8+
#
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
foo
4+
5+
# Expected validation error
6+
#
7+
#Expected an object, but got a scalar value
8+
#
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
[]
4+
5+
# Expected validation error
6+
#
7+
#Expected an object, but got a list
8+
#

0 commit comments

Comments
 (0)