Skip to content

Commit 6bb9d53

Browse files
authored
ci: Make transform test error json easier to diff/review (#2968)
1 parent e88785b commit 6bb9d53

File tree

229 files changed

+1824
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+1824
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ integ-test:
1919

2020
black:
2121
black setup.py samtranslator tests integration bin schema_source
22+
bin/transform-test-error-json-format.py --write tests/translator/output/error_*.json
2223
bin/json-format.py --write tests integration samtranslator/policy_templates_data
2324
bin/yaml-format.py --write tests
2425
bin/yaml-format.py --write integration --add-test-metadata
@@ -30,6 +31,7 @@ black-check:
3031
diff -u schema_source/sam.schema.json .tmp/sam.schema.json
3132
diff -u samtranslator/schema/schema.json .tmp/schema.json
3233
black --check setup.py samtranslator tests integration bin schema_source
34+
bin/transform-test-error-json-format.py --check tests/translator/output/error_*.json
3335
bin/json-format.py --check tests integration samtranslator/policy_templates_data
3436
bin/yaml-format.py --check tests
3537
bin/yaml-format.py --check integration --add-test-metadata
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python
2+
"""
3+
Transform test error JSON file formatter (without prettier).
4+
5+
It makes error json easier to review by breaking down "errorMessage"
6+
into list of strings (delimiter: ". ").
7+
"""
8+
import os
9+
import sys
10+
11+
from typing_extensions import Final
12+
13+
my_path = os.path.dirname(os.path.abspath(__file__))
14+
sys.path.insert(0, my_path + "/..")
15+
16+
import json
17+
from typing import Type
18+
19+
from bin._file_formatter import FileFormatter
20+
21+
22+
class TransformTestErrorJSONFormatter(FileFormatter):
23+
_ERROR_MESSAGE_KEY: Final[str] = "errorMessage"
24+
_BREAKDOWN_ERROR_MESSAGE_KEY: Final[str] = "_autoGeneratedBreakdownErrorMessage"
25+
_DELIMITER: Final[str] = ". "
26+
27+
@staticmethod
28+
def description() -> str:
29+
return "Transform test error JSON file formatter"
30+
31+
def format_str(self, input_str: str) -> str:
32+
"""
33+
It makes error json easier to review by breaking down "errorMessage"
34+
into list of strings (delimiter: ". ").
35+
"""
36+
obj = json.loads(input_str)
37+
error_message = obj.get(self._ERROR_MESSAGE_KEY)
38+
if isinstance(error_message, str):
39+
tokens = error_message.split(self._DELIMITER)
40+
obj[self._BREAKDOWN_ERROR_MESSAGE_KEY] = [
41+
token if index == len(tokens) - 1 else token + self._DELIMITER for index, token in enumerate(tokens)
42+
]
43+
return json.dumps(obj, indent=2, sort_keys=True) + "\n"
44+
45+
@staticmethod
46+
def decode_exception() -> Type[Exception]:
47+
return json.JSONDecodeError
48+
49+
@staticmethod
50+
def file_extension() -> str:
51+
return ".json"
52+
53+
54+
if __name__ == "__main__":
55+
TransformTestErrorJSONFormatter.main()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Structure of the SAM template is invalid. ",
6+
"Value of '/' path must be a dictionary according to Swagger spec."
7+
],
28
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/' path must be a dictionary according to Swagger spec."
39
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Structure of the SAM template is invalid. ",
6+
"Value of '/' path must be a dictionary according to Swagger spec."
7+
],
28
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/' path must be a dictionary according to Swagger spec."
39
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 2. ",
5+
"Resource with id [MyApi] is invalid. ",
6+
"Property 'Authorizers.MyLambdaAuthUpdated.Identity.Headers[0]' should be a string. ",
7+
"Resource with id [MyApi2] is invalid. ",
8+
"Property 'Authorizers.MyLambdaAuthUpdated.Identity.QueryStrings' should be a list."
9+
],
210
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyApi] is invalid. Property 'Authorizers.MyLambdaAuthUpdated.Identity.Headers[0]' should be a string. Resource with id [MyApi2] is invalid. Property 'Authorizers.MyLambdaAuthUpdated.Identity.QueryStrings' should be a list."
311
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 4. ",
5+
"Resource with id [MyApi] is invalid. ",
6+
"Property 'Auth.Authorizers.MyLambdaAuthUpdated.Identity' should be a map. ",
7+
"Resource with id [MyRestApi] is invalid. ",
8+
"Property 'Authorizer.LambdaRequestIdentityNotObject.Identity' should be a map. ",
9+
"Resource with id [MyRestApiInvalidHeadersItemType] is invalid. ",
10+
"Property 'Auth.Authorizers.LambdaRequestIdentityNotObject.Identity.Headers[1]' should be a string. ",
11+
"Resource with id [MyRestApiInvalidHeadersType] is invalid. ",
12+
"Property 'Auth.Authorizers.LambdaRequestIdentityNotObject.Identity.Headers' should be a list."
13+
],
214
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 4. Resource with id [MyApi] is invalid. Property 'Auth.Authorizers.MyLambdaAuthUpdated.Identity' should be a map. Resource with id [MyRestApi] is invalid. Property 'Authorizer.LambdaRequestIdentityNotObject.Identity' should be a map. Resource with id [MyRestApiInvalidHeadersItemType] is invalid. Property 'Auth.Authorizers.LambdaRequestIdentityNotObject.Identity.Headers[1]' should be a string. Resource with id [MyRestApiInvalidHeadersType] is invalid. Property 'Auth.Authorizers.LambdaRequestIdentityNotObject.Identity.Headers' should be a list."
315
}

tests/translator/output/error_api_duplicate_methods_same_path.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Resource with id [Function2] is invalid. ",
6+
"Event with id [GetHtml] is invalid. ",
7+
"API method \"post\" defined multiple times for path \"/add\"."
8+
],
29
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function2] is invalid. Event with id [GetHtml] is invalid. API method \"post\" defined multiple times for path \"/add\".",
310
"errors": [
411
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Resource with id [Function] is invalid. ",
6+
"Event with id [GetHtml] is invalid. ",
7+
"Property 'RestApiId' should be a string."
8+
],
29
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Event with id [GetHtml] is invalid. Property 'RestApiId' should be a string."
310
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Resource with id [MyFunction] is invalid. ",
6+
"Event with id [Event1] is invalid. ",
7+
"RestApiId must be a valid reference to an 'AWS::Serverless::Api' resource in same template."
8+
],
29
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [Event1] is invalid. RestApiId must be a valid reference to an 'AWS::Serverless::Api' resource in same template."
310
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Resource with id [RestApi] is invalid. ",
6+
"Attribute 'Properties' should be a map."
7+
],
28
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [RestApi] is invalid. Attribute 'Properties' should be a map."
39
}

0 commit comments

Comments
 (0)