-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test for CfnIacImplementation.read_project #8296
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
Open
Sanenelisiwe1975
wants to merge
2
commits into
aws:develop
Choose a base branch
from
Sanenelisiwe1975:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| from unittest import TestCase | ||
| from unittest.mock import Mock, MagicMock | ||
| from unittest.mock import MagicMock | ||
| import tempfile | ||
| import os | ||
| import yaml | ||
|
|
||
| from samcli.lib.iac.cdk.cdk_iac import CdkIacImplementation | ||
| from samcli.lib.iac.cfn.cfn_iac import CfnIacImplementation | ||
| from samcli.lib.iac.plugins_interfaces import SamCliContext, LookupPath | ||
|
|
||
|
|
||
| # TODO: Implement these tests when the classes are fully implemented | ||
|
|
@@ -11,14 +14,52 @@ class TestImplementations(TestCase): | |
| def test_cfn_implementation(self): | ||
| impl = CfnIacImplementation(MagicMock()) | ||
| impl.get_iac_file_patterns() | ||
| impl.update_packaged_locations(Mock()) | ||
| impl.write_project(Mock(), Mock()) | ||
| impl.update_packaged_locations(MagicMock()) | ||
| impl.write_project(MagicMock(), MagicMock()) | ||
| self.assertTrue(True) | ||
|
|
||
| def test_cdk_implementation(self): | ||
| impl = CdkIacImplementation(Mock()) | ||
| impl = CfnIacImplementation(MagicMock()) | ||
| impl.get_iac_file_patterns() | ||
| impl.read_project(Mock()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to delete this |
||
| impl.update_packaged_locations(Mock()) | ||
| impl.write_project(Mock(), Mock()) | ||
| impl.update_packaged_locations(MagicMock()) | ||
| impl.write_project(MagicMock(), MagicMock()) | ||
| self.assertTrue(True) | ||
|
|
||
| def test_read_project_minimal_template(self): | ||
| # Create a minimal CloudFormation template | ||
| minimal_template = { | ||
| "AWSTemplateFormatVersion": "2010-09-09", | ||
| "Resources": { | ||
| "MyFunction": { | ||
| "Type": "AWS::Serverless::Function", | ||
| "Properties": { | ||
| "Handler": "index.handler", | ||
| "Runtime": "python3.8", | ||
| "CodeUri": "./src" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| template_path = os.path.join(tmpdir, "template.yaml") | ||
| with open(template_path, "w") as f: | ||
| yaml.dump(minimal_template, f) | ||
|
|
||
| context = SamCliContext( | ||
| command_options_map={"template_file": template_path}, | ||
| sam_command_name="test", | ||
| is_guided=False, | ||
| is_debugging=False, | ||
| profile=None, | ||
| region=None | ||
| ) | ||
| impl = CfnIacImplementation(context) | ||
| lookup_paths = [LookupPath(tmpdir)] | ||
| project = impl.read_project(lookup_paths) | ||
|
|
||
| # Assert the project contains one stack with the expected resource | ||
| self.assertEqual(len(project.stacks), 1) | ||
| stack = project.stacks[0] | ||
| self.assertIn("Resources", stack) | ||
| resources = stack["Resources"].section_items | ||
| self.assertTrue(any(r.item_id == "MyFunction" for r in resources)) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why this is changed?