diff --git a/src/jvmTest/kotlin/it/krzeminski/githubactionstyping/LogicConsistencyTest.kt b/src/jvmTest/kotlin/it/krzeminski/githubactionstyping/LogicConsistencyTest.kt index ea3eac9..f9c8569 100644 --- a/src/jvmTest/kotlin/it/krzeminski/githubactionstyping/LogicConsistencyTest.kt +++ b/src/jvmTest/kotlin/it/krzeminski/githubactionstyping/LogicConsistencyTest.kt @@ -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 @@ -29,14 +31,23 @@ class LogicConsistencyTest : UseCaseTest() { .trimMargin("#") .trim() - val validationResult = parseTypesManifest(typesManifest).validate(typing.toPath().fileName) - assertSoftly { - validationResult.overallResult should beOfType() - 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() + validationResult + .toPlaintextReport() + .trim() + .replace("\u001B", "\\x1B") + .shouldBe(expectedValidationError) + } } } } diff --git a/src/test/resources/bad-typings/inputs_enum_list_item_with_non_sequence_allowed_values.yml b/src/test/resources/bad-typings/inputs_enum_list_item_with_non_sequence_allowed_values.yml new file mode 100644 index 0000000..d2c65a0 --- /dev/null +++ b/src/test/resources/bad-typings/inputs_enum_list_item_with_non_sequence_allowed_values.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/inputs_enum_with_non_sequence_allowed_values.yml b/src/test/resources/bad-typings/inputs_enum_with_non_sequence_allowed_values.yml new file mode 100644 index 0000000..5431708 --- /dev/null +++ b/src/test/resources/bad-typings/inputs_enum_with_non_sequence_allowed_values.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/inputs_integer_list_item_with_non_mapping_named_values.yml b/src/test/resources/bad-typings/inputs_integer_list_item_with_non_mapping_named_values.yml new file mode 100644 index 0000000..c32e545 --- /dev/null +++ b/src/test/resources/bad-typings/inputs_integer_list_item_with_non_mapping_named_values.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/inputs_integer_with_non_mapping_named_values.yml b/src/test/resources/bad-typings/inputs_integer_with_non_mapping_named_values.yml new file mode 100644 index 0000000..c03426c --- /dev/null +++ b/src/test/resources/bad-typings/inputs_integer_with_non_mapping_named_values.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/inputs_list_with_null_separator.yml b/src/test/resources/bad-typings/inputs_list_with_null_separator.yml new file mode 100644 index 0000000..420190c --- /dev/null +++ b/src/test/resources/bad-typings/inputs_list_with_null_separator.yml @@ -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. +# diff --git a/src/test/resources/bad-typings/inputs_with_non_string_type.yml b/src/test/resources/bad-typings/inputs_with_non_string_type.yml new file mode 100644 index 0000000..ce28b33 --- /dev/null +++ b/src/test/resources/bad-typings/inputs_with_non_string_type.yml @@ -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. +# diff --git a/src/test/resources/bad-typings/inputs_with_null_type.yml b/src/test/resources/bad-typings/inputs_with_null_type.yml new file mode 100644 index 0000000..1888851 --- /dev/null +++ b/src/test/resources/bad-typings/inputs_with_null_type.yml @@ -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. +# diff --git a/src/test/resources/bad-typings/outputs_enum_list_item_with_non_sequence_allowed_values.yml b/src/test/resources/bad-typings/outputs_enum_list_item_with_non_sequence_allowed_values.yml new file mode 100644 index 0000000..bb77efe --- /dev/null +++ b/src/test/resources/bad-typings/outputs_enum_list_item_with_non_sequence_allowed_values.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/outputs_enum_with_non_sequence_allowed_values.yml b/src/test/resources/bad-typings/outputs_enum_with_non_sequence_allowed_values.yml new file mode 100644 index 0000000..4ab8eb8 --- /dev/null +++ b/src/test/resources/bad-typings/outputs_enum_with_non_sequence_allowed_values.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/outputs_integer_list_item_with_non_mapping_named_values.yml b/src/test/resources/bad-typings/outputs_integer_list_item_with_non_mapping_named_values.yml new file mode 100644 index 0000000..9ed760b --- /dev/null +++ b/src/test/resources/bad-typings/outputs_integer_list_item_with_non_mapping_named_values.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/outputs_integer_with_non_mapping_named_values.yml b/src/test/resources/bad-typings/outputs_integer_with_non_mapping_named_values.yml new file mode 100644 index 0000000..e171a55 --- /dev/null +++ b/src/test/resources/bad-typings/outputs_integer_with_non_mapping_named_values.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/outputs_list_with_null_separator.yml b/src/test/resources/bad-typings/outputs_list_with_null_separator.yml new file mode 100644 index 0000000..3cc1026 --- /dev/null +++ b/src/test/resources/bad-typings/outputs_list_with_null_separator.yml @@ -0,0 +1,22 @@ +# 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 +# diff --git a/src/test/resources/bad-typings/outputs_with_non_string_type.yml b/src/test/resources/bad-typings/outputs_with_non_string_type.yml new file mode 100644 index 0000000..ad3173b --- /dev/null +++ b/src/test/resources/bad-typings/outputs_with_non_string_type.yml @@ -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 +# +# diff --git a/src/test/resources/bad-typings/outputs_with_null_type.yml b/src/test/resources/bad-typings/outputs_with_null_type.yml new file mode 100644 index 0000000..7b21138 --- /dev/null +++ b/src/test/resources/bad-typings/outputs_with_null_type.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/scalar_input.yml b/src/test/resources/bad-typings/scalar_input.yml new file mode 100644 index 0000000..14ce19d --- /dev/null +++ b/src/test/resources/bad-typings/scalar_input.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/scalar_inputs.yml b/src/test/resources/bad-typings/scalar_inputs.yml new file mode 100644 index 0000000..40ebe8a --- /dev/null +++ b/src/test/resources/bad-typings/scalar_inputs.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/scalar_output.yml b/src/test/resources/bad-typings/scalar_output.yml new file mode 100644 index 0000000..39fb840 --- /dev/null +++ b/src/test/resources/bad-typings/scalar_output.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/scalar_outputs.yml b/src/test/resources/bad-typings/scalar_outputs.yml new file mode 100644 index 0000000..feffa83 --- /dev/null +++ b/src/test/resources/bad-typings/scalar_outputs.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/sequence_input.yml b/src/test/resources/bad-typings/sequence_input.yml new file mode 100644 index 0000000..9b65e6e --- /dev/null +++ b/src/test/resources/bad-typings/sequence_input.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/sequence_inputs.yml b/src/test/resources/bad-typings/sequence_inputs.yml new file mode 100644 index 0000000..340f9d8 --- /dev/null +++ b/src/test/resources/bad-typings/sequence_inputs.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/sequence_output.yml b/src/test/resources/bad-typings/sequence_output.yml new file mode 100644 index 0000000..3448f20 --- /dev/null +++ b/src/test/resources/bad-typings/sequence_output.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/sequence_outputs.yml b/src/test/resources/bad-typings/sequence_outputs.yml new file mode 100644 index 0000000..65ed657 --- /dev/null +++ b/src/test/resources/bad-typings/sequence_outputs.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/top_level_scalar.yml b/src/test/resources/bad-typings/top_level_scalar.yml new file mode 100644 index 0000000..0a05d5b --- /dev/null +++ b/src/test/resources/bad-typings/top_level_scalar.yml @@ -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 +# diff --git a/src/test/resources/bad-typings/top_level_sequence.yml b/src/test/resources/bad-typings/top_level_sequence.yml new file mode 100644 index 0000000..f5fff6a --- /dev/null +++ b/src/test/resources/bad-typings/top_level_sequence.yml @@ -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 +#