Skip to content

Commit

Permalink
Refactoring resource spec, updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
syldyer committed Oct 10, 2024
1 parent 1e9c652 commit 3589df9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
28 changes: 17 additions & 11 deletions src/rpdk/core/data_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,8 @@ def load_resource_spec( # pylint: disable=R # noqa: C901
resource_spec_file, original_schema_raw=None
):
"""Load a resource provider definition from a file, and validate it."""
original_resource_spec = None
try:
resource_spec = json.load(resource_spec_file)
if original_schema_raw:
print(
"Type Exists in CloudFormation Registry. "
"Evaluating Resource Schema Backward Compatibility Compliance",
)
original_resource_spec = json.loads(original_schema_raw)
sgr_stateful_eval(resource_spec, original_resource_spec)

print("Evaluating Resource Schema Compliance")
sgr_stateless_eval(resource_spec)

except ValueError as e:
LOG.debug("Resource spec decode failed", exc_info=True)
Expand Down Expand Up @@ -425,6 +414,23 @@ def load_resource_spec( # pylint: disable=R # noqa: C901
LOG.debug("Inlined schema is no longer valid", exc_info=True)
raise InternalError() from e

LOG.warning(
"Resource schema metadata is valid. Running a schema compliance evaluation:\n"
)

# Run SGR checks once Schema Metadata is checked
original_resource_spec = None
if original_schema_raw:
print(
"Type Exists in CloudFormation Registry. "
"Evaluating Resource Schema Backward Compatibility Compliance",
)
original_resource_spec = json.loads(original_schema_raw)
sgr_stateful_eval(resource_spec, original_resource_spec)

print("Evaluating Resource Schema Compliance")
sgr_stateless_eval(resource_spec)

return inlined


Expand Down
2 changes: 1 addition & 1 deletion src/rpdk/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def validate_and_load_resource_settings(self, raw_settings):
self.entrypoint = raw_settings["entrypoint"]
self.test_entrypoint = raw_settings["testEntrypoint"]
self.executable_entrypoint = raw_settings.get("executableEntrypoint")
# self._plugin = load_plugin(raw_settings["language"])
self._plugin = load_plugin(raw_settings["language"])
self.settings = raw_settings.get("settings", {})
self.canary_settings = raw_settings.get("canarySettings", {})

Expand Down
8 changes: 5 additions & 3 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def test_configuration_schema_filename(project):
)


# TODO:
def test_load_schema_with_typeconfiguration(project):
patch_settings = patch.object(project, "load_settings")
patch_schema = patch.object(project, "load_schema")
Expand All @@ -439,7 +440,7 @@ def test_load_schema_with_typeconfiguration(project):
project.load()

mock_settings.assert_called_once_with()
mock_schema.assert_called_once_with()
mock_schema.assert_called_once_with(None)
mock_configuration_schema.assert_called_once_with()


Expand Down Expand Up @@ -1190,6 +1191,7 @@ def test_init_module(project):
assert f.read() == b"\n"


# TODO:
def test_load_invalid_schema(project):
patch_settings = patch.object(project, "load_settings")
patch_schema = patch.object(
Expand All @@ -1201,7 +1203,7 @@ def test_load_invalid_schema(project):
project.load()

mock_settings.assert_called_once_with()
mock_schema.assert_called_once_with()
mock_schema.assert_called_once_with(None)

assert "invalid" in str(excinfo.value)

Expand Down Expand Up @@ -1292,7 +1294,7 @@ def test_schema_not_found(project):
project.load()

mock_settings.assert_called_once_with()
mock_schema.assert_called_once_with()
mock_schema.assert_called_once_with(None)

assert "not found" in str(excinfo.value)

Expand Down

0 comments on commit 3589df9

Please sign in to comment.