8000 test: add some bad typings test cases by Vampire · Pull Request #289 · typesafegithub/github-actions-typing · GitHub
[go: up one dir, main page]

Skip to content

test: add some bad typings test cases #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package it.krzeminski.githubactionstyping

import com.charleskorn.kaml.IncorrectTypeException
import com.charleskorn.kaml.InvalidPropertyValueException
import io.kotest.assertions.assertSoftly
import io.kotest.assertions.withClue
import io.kotest.matchers.should
Expand Down Expand Up @@ -29,14 +31,23 @@ class LogicConsistencyTest : UseCaseTest() {
.trimMargin("#")
.trim()

val validationResult = parseTypesManifest(typesManifest).validate(typing.toPath().fileName)
assertSoftly {
validationResult.overallResult should beOfType<ItemValidationResult.Invalid>()
validationResult
.toPlaintextReport()
.trim()
.replace("\u001B", "\\x1B")
.shouldBe(expectedValidationError)
val parsedTypesManifest = runCatching {
parseTypesManifest(typesManifest).validate(typing.toPath().fileName)
}
if (parsedTypesManifest.isFailure &&
((parsedTypesManifest.exceptionOrNull() is InvalidPropertyValueException) || (parsedTypesManifest.exceptionOrNull() is IncorrectTypeException))
) {
parsedTypesManifest.exceptionOrNull()!!.message shouldBe expectedValidationError
} else {
val validationResult = parsedTypesManifest.getOrThrow()
assertSoftly {
validationResult.overallResult should beOfType<ItemValidationResult.Invalid>()
validationResult
.toPlaintextReport()
.trim()
.replace("\u001B", "\\x1B")
.shouldBe(expectedValidationError)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs:
granted-scopes:
type: list
separator: ','
list-item:
type: enum
allowed-values: foo

# Expected validation error
#
#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
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs:
permissions:
type: enum
allowed-values: foo

# Expected validation error
#
#Value for 'inputs' is invalid: Value for 'permissions' is invalid: Value for 'allowed-values' is invalid: Expected a list, but got a scalar value
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs:
list-of-integer:
type: list
separator: ','
list-item:
type: integer
name: AllowedValues
named-values: []

# Expected validation error
#
#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
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs:
retries:
type: integer
name: AllowedValues
named-values: []

# Expected validation error
#
#Value for 'inputs' is invalid: Value for 'retries' is invalid: Value for 'named-values' is invalid: Expected a map, but got a list
#
22 changes: 22 additions & 0 deletions src/test/resources/bad-typings/inputs_list_with_null_separator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs:
input-files:
type: list
separator:
list-item:
type: string

# Expected validation error
#
#For action with manifest at 'inputs_list_with_null_separator.yml':
#Result:
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
#
#Inputs:
#• input-files:
# \x1B[31m❌ INVALID: Separator must be specified.\x1B[0m
#
#Outputs:
#None.
#
19 changes: 19 additions & 0 deletions src/test/resources/bad-typings/inputs_with_non_string_type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs:
permissions:
type: 0x0

# Expected validation error
#
#For action with manifest at 'inputs_with_non_string_type.yml':
#Result:
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
#
#Inputs:
#• permissions:
# \x1B[31m❌ INVALID: Unknown type: '0x0'.\x1B[0m
#
#Outputs:
#None.
#
19 changes: 19 additions & 0 deletions src/test/resources/bad-typings/inputs_with_null_type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs:
permissions:
type:

# Expected validation error
#
#For action with manifest at 'inputs_with_null_type.yml':
#Result:
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
#
#Inputs:
#• permissions:
# \x1B[31m❌ INVALID: Type must be specified. Use 'type' attribute.\x1B[0m
#
#Outputs:
#None.
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs:
granted-scopes:
type: list
separator: ','
list-item:
type: enum
allowed-values: foo

# Expected validation error
#
#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
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs:
permissions:
type: enum
allowed-values: foo

# Expected validation error
#
#Value for 'outputs' is invalid: Value for 'permissions' is invalid: Value for 'allowed-values' is invalid: Expected a list, but got a scalar value
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs:
list-of-integer:
type: list
separator: ','
list-item:
type: integer
named-values: []

# Expected validation error
#
#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
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs:
retries:
type: integer
named-values: []

# Expected validation error
#
#Value for 'outputs' is invalid: Value for 'retries' is invalid: Value for 'named-values' is invalid: Expected a map, but got a list
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@ 10000
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs:
input-files:
type: list
separator:
list-item:
type: string

# Expected validation error
#
#For action with manifest at 'outputs_list_with_null_separator.yml':
#Result:
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
#
#Inputs:
#None.
#
#Outputs:
#• input-files:
# \x1B[31m❌ INVALID: Separator must be specified.\x1B[0m
#
20 changes: 20 additions & 0 deletions src/test/resources/bad-typings/outputs_with_non_string_type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs:
permissions:
type: 0x0

# Expected validation error
#
#For action with manifest at 'outputs_with_non_string_type.yml':
#Result:
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
#
#Inputs:
#None.
#
#Outputs:
#• permissions:
# \x1B[31m❌ INVALID: Unknown type: '0x0'.\x1B[0m
#
#
19 changes: 19 additions & 0 deletions src/test/resources/bad-typings/outputs_with_null_type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs:
permissions:
type:

# Expected validation error
#
#For action with manifest at 'outputs_with_null_type.yml':
#Result:
#\x1B[31m❌ INVALID: Some typing is invalid.\x1B[0m
#
#Inputs:
#None.
#
#Outputs:
#• permissions:
# \x1B[31m❌ INVALID: Type must be specified. Use 'type' attribute.\x1B[0m
#
9 changes: 9 additions & 0 deletions src/test/resources/bad-typings/scalar_input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs:
foo: bar

# Expected validation error
#
#Value for 'inputs' is invalid: Value for 'foo' is invalid: Expected an object, but got a scalar value
#
8 changes: 8 additions & 0 deletions src/test/resources/bad-typings/scalar_inputs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs: foo

# Expected validation error
#
#Value for 'inputs' is invalid: Expected a map, but got a scalar value
#
9 changes: 9 additions & 0 deletions src/test/resources/bad-typings/scalar_output.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs:
foo: bar

# Expected validation error
#
#Value for 'outputs' is invalid: Value for 'foo' is invalid: Expected an object, but got a scalar value
#
8 changes: 8 additions & 0 deletions src/test/resources/bad-typings/scalar_outputs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs: foo

# Expected validation error
#
#Value for 'outputs' is invalid: Expected a map, but got a scalar value
#
9 changes: 9 additions & 0 deletions src/test/resources/bad-typings/sequence_input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs:
foo: []

# Expected validation error
#
#Value for 'inputs' is invalid: Value for 'foo' is invalid: Expected an object, but got a list
#
8 changes: 8 additions & 0 deletions src/test/resources/bad-typings/sequence_inputs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
inputs: []

# Expected validation error
#
#Value for 'inputs' is invalid: Expected a map, but got a list
#
9 changes: 9 additions & 0 deletions src/test/resources/bad-typings/sequence_output.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs:
foo: []

# Expected validation error
#
#Value for 'outputs' is invalid: Value for 'foo' is invalid: Expected an object, but got a list
#
8 changes: 8 additions & 0 deletions src/test/resources/bad-typings/sequence_outputs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
outputs: []

# Expected validation error
#
#Value for 'outputs' is invalid: Expected a map, but got a list
#
8 changes: 8 additions & 0 deletions src/test/resources/bad-typings/top_level_scalar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
foo

# Expected validation error
#
#Expected an object, but got a scalar value
#
8 changes: 8 additions & 0 deletions src/test/resources/bad-typings/top_level_sequence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
# See https://github.com/typesafegithub/github-actions-typing
[]

# Expected validation error
#
#Expected an object, but got a list
#
Loading
0