-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[SFN] [TestState] Add mock result validation according to field validation modes #13419
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
[SFN] [TestState] Add mock result validation according to field validation modes #13419
Conversation
strict field validation mode
strict field validation modeSTRICT field validation mode
LocalStack Community integration with Pro 2 files ± 0 2 suites ±0 20m 32s ⏱️ - 1h 40m 17s Results for commit 3952452. ± Comparison against base commit 58f49e9. ♻️ This comment has been updated with latest results. |
Test Results (amd64) - Integration, Bootstrap 5 files ± 0 5 suites ±0 39m 6s ⏱️ - 2h 2m 8s Results for commit 3952452. ± Comparison against base commit 58f49e9. ♻️ This comment has been updated with latest results. |
7bf7ea6 to
c5d5aab
Compare
957a2e0 to
08d99fe
Compare
gregfurman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice one addressing these (frankly, extremely) complex validation cases!
Could be worth looking into using a pydantic model to easier validate this JSON like I did in:
localstack/localstack-core/localstack/services/stepfunctions/backend/test_state/test_state_mock.py
Lines 101 to 106 in 7f544bb
| def parse_context(context: str, state_type: StateType = None) -> ContextObjectData: | |
| """Parse and validate context JSON string.""" | |
| try: | |
| validation_result = TestStateContextObjectValidator.model_validate_json(context) | |
| return validation_result.model_dump(exclude_unset=True, exclude_none=True) | |
| except ValidationError as e: |
| return test_program.test_state is not None | ||
|
|
||
| @staticmethod | ||
| def validate_mock(mock: TestStateMock, definition: Definition, state_name: StateName) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok wow. This is gnarly 💀
...core/localstack/services/stepfunctions/asl/static_analyser/test_state/test_state_analyser.py
Show resolved
Hide resolved
STRICT field validation mode48462aa to
3952452
Compare
TestState validates mocked responses against AWS API models with three validation modes: STRICT (this is the default and validates all required fields), PRESENT (validates field types and names), and NONE (no validation). STRICT field validation mode checks the presence of required fields and validates the type and format of the fields in the mock against the respective service shape in AWS API definitions. PRESENT field validation mode doesn't check the presence of required fields. It only validates the type and format of the fields that are present in the user-provided mock. NONE mode means no format validation will be performed. A check that the result is a valid JSON string is still performed even in NONE field validation mode. Note: fields that are not present in the API spec but are supplied in the mock will be allowed, because of forward-compatibility.
3952452 to
06902e0
Compare
5eb1f18
into
feature/step-functions/test-state-main
Motivation
TestState validates mocked responses against AWS API models with three validation modes: STRICT (this is the default and validates all required fields), PRESENT (validates field types and names), and NONE (no validation).
STRICTfield validation mode checks the presence of required fields and validates the type and format of the fields in the mock against the respective service shape in AWS API definitions.PRESENTfield validation mode doesn't check the presence of required fields. It only validates the type and format of the fields that are present in the user-provided mock.NONEmode means no format validation will be performed. A check that the result is a valid JSON string is still performed even in NONE field validation mode.Note: fields that are not present in the API spec but are supplied in the mock will be allowed, because of forward-compatibility.
Closes DRG-220.
Changes
Add mock result validation method to a static analyzer that already contains several other validations.
Limitations:
range/length validation is not implemented yet (added DRG-258 as a follow-up)
Tests
Related