-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: use resource type instead of resource id for deciding zip method #4485
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
Merged
Merged
Changes from all commits
Commits
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -164,11 +164,22 @@ def _helper_verify_export_resources( | |
| LambdaLayerVersionResource, | ||
| ): | ||
| upload_local_artifacts_mock.assert_called_once_with( | ||
| resource_id, resource_dict, test_class.PROPERTY_NAME, parent_dir, s3_uploader_mock | ||
| test_class.RESOURCE_TYPE, | ||
| resource_id, | ||
| resource_dict, | ||
| test_class.PROPERTY_NAME, | ||
| parent_dir, | ||
| s3_uploader_mock, | ||
| ) | ||
| else: | ||
| upload_local_artifacts_mock.assert_called_once_with( | ||
| resource_id, resource_dict, test_class.PROPERTY_NAME, parent_dir, s3_uploader_mock, None | ||
| test_class.RESOURCE_TYPE, | ||
| resource_id, | ||
| resource_dict, | ||
| test_class.PROPERTY_NAME, | ||
| parent_dir, | ||
| s3_uploader_mock, | ||
| None, | ||
| ) | ||
| code_signer_mock.sign_package.assert_not_called() | ||
| if "." in test_class.PROPERTY_NAME: | ||
|
|
@@ -272,6 +283,7 @@ def test_upload_local_artifacts_local_file(self, zip_and_upload_mock): | |
| # Verifies that we package local artifacts appropriately | ||
| property_name = "property" | ||
| resource_id = "resource_id" | ||
| resource_type = "resource_type" | ||
| expected_s3_url = "s3://foo/bar?versionId=baz" | ||
|
|
||
| self.s3_uploader_mock.upload_with_dedup.return_value = expected_s3_url | ||
|
|
@@ -283,7 +295,7 @@ def test_upload_local_artifacts_local_file(self, zip_and_upload_mock): | |
|
|
||
| resource_dict = {property_name: artifact_path} | ||
| result = upload_local_artifacts( | ||
| resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock | ||
| resource_type, resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock | ||
| ) | ||
| self.assertEqual(result, expected_s3_url) | ||
|
|
||
|
|
@@ -300,6 +312,7 @@ def test_upload_local_artifacts_local_file_abs_path(self, zip_and_upload_mock): | |
| # Verifies that we package local artifacts appropriately | ||
| property_name = "property" | ||
| resource_id = "resource_id" | ||
| resource_type = "resource_type" | ||
| expected_s3_url = "s3://foo/bar?versionId=baz" | ||
|
|
||
| self.s3_uploader_mock.upload_with_dedup.return_value = expected_s3_url | ||
|
|
@@ -310,7 +323,7 @@ def test_upload_local_artifacts_local_file_abs_path(self, zip_and_upload_mock): | |
|
|
||
| resource_dict = {property_name: artifact_path} | ||
| result = upload_local_artifacts( | ||
| resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock | ||
| resource_type, resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock | ||
| ) | ||
| self.assertEqual(result, expected_s3_url) | ||
|
|
||
|
|
@@ -321,6 +334,7 @@ def test_upload_local_artifacts_local_file_abs_path(self, zip_and_upload_mock): | |
| def test_upload_local_artifacts_local_folder(self, zip_and_upload_mock): | ||
| property_name = "property" | ||
| resource_id = "resource_id" | ||
| resource_type = "resource_type" | ||
| expected_s3_url = "s3://foo/bar?versionId=baz" | ||
|
|
||
| zip_and_upload_mock.return_value = expected_s3_url | ||
|
|
@@ -331,7 +345,9 @@ def test_upload_local_artifacts_local_folder(self, zip_and_upload_mock): | |
| parent_dir = tempfile.gettempdir() | ||
| resource_dict = {property_name: artifact_path} | ||
|
|
||
| result = upload_local_artifacts(resource_id, resource_dict, property_name, parent_dir, Mock()) | ||
| result = upload_local_artifacts( | ||
| resource_type, resource_id, resource_dict, property_name, parent_dir, Mock() | ||
| ) | ||
| self.assertEqual(result, expected_s3_url) | ||
|
|
||
| absolute_artifact_path = make_abs_path(parent_dir, artifact_path) | ||
|
|
@@ -340,8 +356,9 @@ def test_upload_local_artifacts_local_folder(self, zip_and_upload_mock): | |
|
|
||
| @patch("samcli.lib.package.utils.zip_and_upload") | ||
| def test_upload_local_artifacts_local_folder_lambda_resources(self, zip_and_upload_mock): | ||
| for resource_id in LAMBDA_LOCAL_RESOURCES: | ||
| for resource_type in LAMBDA_LOCAL_RESOURCES: | ||
|
Contributor
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. Looks like this was full-filling test before then.. Thanks for the fix! |
||
| property_name = "property" | ||
| resource_id = "resource_id" | ||
| expected_s3_url = "s3://foo/bar?versionId=baz" | ||
|
|
||
| zip_and_upload_mock.return_value = expected_s3_url | ||
|
|
@@ -351,7 +368,9 @@ def test_upload_local_artifacts_local_folder_lambda_resources(self, zip_and_uplo | |
| parent_dir = tempfile.gettempdir() | ||
| resource_dict = {property_name: artifact_path} | ||
|
|
||
| result = upload_local_artifacts(resource_id, resource_dict, property_name, parent_dir, Mock()) | ||
| result = upload_local_artifacts( | ||
| resource_type, resource_id, resource_dict, property_name, parent_dir, Mock() | ||
| ) | ||
| self.assertEqual(result, expected_s3_url) | ||
|
|
||
| absolute_artifact_path = make_abs_path(parent_dir, artifact_path) | ||
|
|
@@ -371,8 +390,9 @@ def test_upload_local_artifacts_local_folder_lambda_resources(self, zip_and_uplo | |
| @patch("samcli.lib.package.utils.zip_and_upload") | ||
| def test_upload_local_artifacts_local_folder_non_lambda_resources(self, zip_and_upload_mock): | ||
| non_lambda_resources = RESOURCES_WITH_LOCAL_PATHS.keys() - LAMBDA_LOCAL_RESOURCES | ||
| for resource_id in non_lambda_resources: | ||
| for resource_type in non_lambda_resources: | ||
| property_name = "property" | ||
| resource_id = "resource_id" | ||
| expected_s3_url = "s3://foo/bar?versionId=baz" | ||
|
|
||
| zip_and_upload_mock.return_value = expected_s3_url | ||
|
|
@@ -382,7 +402,9 @@ def test_upload_local_artifacts_local_folder_non_lambda_resources(self, zip_and_ | |
| parent_dir = tempfile.gettempdir() | ||
| resource_dict = {property_name: artifact_path} | ||
|
|
||
| result = upload_local_artifacts(resource_id, resource_dict, property_name, parent_dir, Mock()) | ||
| result = upload_local_artifacts( | ||
| resource_type, resource_id, resource_dict, property_name, parent_dir, Mock() | ||
| ) | ||
| self.assertEqual(result, expected_s3_url) | ||
|
|
||
| absolute_artifact_path = make_abs_path(parent_dir, artifact_path) | ||
|
|
@@ -401,6 +423,7 @@ def test_upload_local_artifacts_local_folder_non_lambda_resources(self, zip_and_ | |
| def test_upload_local_artifacts_no_path(self, zip_and_upload_mock): | ||
| property_name = "property" | ||
| resource_id = "resource_id" | ||
| resource_type = "resource_type" | ||
| expected_s3_url = "s3://foo/bar?versionId=baz" | ||
|
|
||
| zip_and_upload_mock.return_value = expected_s3_url | ||
|
|
@@ -409,7 +432,9 @@ def test_upload_local_artifacts_no_path(self, zip_and_upload_mock): | |
| resource_dict = {} | ||
| parent_dir = tempfile.gettempdir() | ||
|
|
||
| result = upload_local_artifacts(resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock) | ||
| result = upload_local_artifacts( | ||
| resource_type, resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock | ||
| ) | ||
| self.assertEqual(result, expected_s3_url) | ||
|
|
||
| zip_and_upload_mock.assert_called_once_with(parent_dir, mock.ANY, None, zip_method=make_zip) | ||
|
|
@@ -419,13 +444,16 @@ def test_upload_local_artifacts_no_path(self, zip_and_upload_mock): | |
| def test_upload_local_artifacts_s3_url(self, zip_and_upload_mock): | ||
| property_name = "property" | ||
| resource_id = "resource_id" | ||
| resource_type = "resource_type" | ||
| object_s3_url = "s3://foo/bar?versionId=baz" | ||
|
|
||
| # If URL is already S3 URL, this will be returned without zip/upload | ||
| resource_dict = {property_name: object_s3_url} | ||
| parent_dir = tempfile.gettempdir() | ||
|
|
||
| result = upload_local_artifacts(resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock) | ||
| result = upload_local_artifacts( | ||
| resource_type, resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock | ||
| ) | ||
| self.assertEqual(result, object_s3_url) | ||
|
|
||
| zip_and_upload_mock.assert_not_called() | ||
|
|
@@ -435,17 +463,22 @@ def test_upload_local_artifacts_s3_url(self, zip_and_upload_mock): | |
| def test_upload_local_artifacts_invalid_value(self, zip_and_upload_mock): | ||
| property_name = "property" | ||
| resource_id = "resource_id" | ||
| resource_type = "resource_type" | ||
| parent_dir = tempfile.gettempdir() | ||
|
|
||
| with self.assertRaises(exceptions.InvalidLocalPathError): | ||
| non_existent_file = "some_random_filename" | ||
| resource_dict = {property_name: non_existent_file} | ||
| upload_local_artifacts(resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock) | ||
| upload_local_artifacts( | ||
| resource_type, resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock | ||
| ) | ||
|
|
||
| with self.assertRaises(exceptions.InvalidLocalPathError): | ||
| non_existent_file = ["invalid datatype"] | ||
| resource_dict = {property_name: non_existent_file} | ||
| upload_local_artifacts(resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock) | ||
| upload_local_artifacts( | ||
| resource_type, resource_id, resource_dict, property_name, parent_dir, self.s3_uploader_mock | ||
| ) | ||
|
|
||
| zip_and_upload_mock.assert_not_called() | ||
| self.s3_uploader_mock.upload_with_dedup.assert_not_called() | ||
|
|
@@ -481,7 +514,13 @@ class MockResource(ResourceZip): | |
| resource.export(resource_id, resource_dict, parent_dir) | ||
|
|
||
| upload_local_artifacts_mock.assert_called_once_with( | ||
| resource_id, resource_dict, resource.PROPERTY_NAME, parent_dir, self.s3_uploader_mock, None | ||
| resource.RESOURCE_TYPE, | ||
| resource_id, | ||
| resource_dict, | ||
| resource.PROPERTY_NAME, | ||
| parent_dir, | ||
| self.s3_uploader_mock, | ||
| None, | ||
| ) | ||
|
|
||
| self.assertEqual(resource_dict[resource.PROPERTY_NAME], s3_url) | ||
|
|
@@ -756,7 +795,13 @@ class MockResource(ResourceZip): | |
| resource_dict = {} | ||
| resource.export(resource_id, resource_dict, parent_dir) | ||
| upload_local_artifacts_mock.assert_called_once_with( | ||
| resource_id, resource_dict, resource.PROPERTY_NAME, parent_dir, self.s3_uploader_mock, None | ||
| resource.RESOURCE_TYPE, | ||
| resource_id, | ||
| resource_dict, | ||
| resource.PROPERTY_NAME, | ||
| parent_dir, | ||
| self.s3_uploader_mock, | ||
| None, | ||
| ) | ||
| self.code_signer_mock.should_sign_package.assert_called_once_with(resource_id) | ||
| self.code_signer_mock.sign_package.assert_not_called() | ||
|
|
@@ -851,7 +896,12 @@ class MockResource(ResourceWithS3UrlDict): | |
| resource.export(resource_id, resource_dict, parent_dir) | ||
|
|
||
| upload_local_artifacts_mock.assert_called_once_with( | ||
| resource_id, resource_dict, resource.PROPERTY_NAME, parent_dir, self.s3_uploader_mock | ||
| resource.RESOURCE_TYPE, | ||
| resource_id, | ||
| resource_dict, | ||
| resource.PROPERTY_NAME, | ||
| parent_dir, | ||
| self.s3_uploader_mock, | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
|
|
||
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.
Let's change this to function instead of layer, and update L136 to be the same
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.
Sorry nevermind this is actually supposed to be layer, but I'm raising a CR to update the validation on L136 to be the same as this one