-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #361 from aws/develop
chore: Merge develop to master
- Loading branch information
Showing
18 changed files
with
349 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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,5 +1,5 @@ | ||
""" | ||
AWS Lambda Builder Library | ||
""" | ||
__version__ = "1.15.0" | ||
__version__ = "1.16.0" | ||
RPC_PROTOCOL_VERSION = "0.3" |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -29,29 +29,30 @@ def setUp(self): | |
self.no_deps = os.path.join(self.TEST_DATA_FOLDER, "no-deps") | ||
|
||
self.builder = LambdaBuilder(language="nodejs", dependency_manager="npm", application_framework=None) | ||
self.runtime = "nodejs12.x" | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.artifacts_dir) | ||
shutil.rmtree(self.scratch_dir) | ||
shutil.rmtree(self.dependencies_dir) | ||
|
||
def test_builds_project_without_dependencies(self): | ||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_builds_project_without_dependencies(self, runtime): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-deps") | ||
|
||
self.builder.build( | ||
source_dir, | ||
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
) | ||
|
||
expected_files = {"package.json", "included.js"} | ||
output_files = set(os.listdir(self.artifacts_dir)) | ||
self.assertEqual(expected_files, output_files) | ||
|
||
def test_builds_project_without_manifest(self): | ||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_builds_project_without_manifest(self, runtime): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-manifest") | ||
|
||
with mock.patch.object(logger, "warning") as mock_warning: | ||
|
@@ -60,38 +61,40 @@ def test_builds_project_without_manifest(self): | |
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
) | ||
|
||
expected_files = {"app.js"} | ||
output_files = set(os.listdir(self.artifacts_dir)) | ||
mock_warning.assert_called_once_with("package.json file not found. Continuing the build without dependencies.") | ||
self.assertEqual(expected_files, output_files) | ||
|
||
def test_builds_project_and_excludes_hidden_aws_sam(self): | ||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_builds_project_and_excludes_hidden_aws_sam(self, runtime): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "excluded-files") | ||
|
||
self.builder.build( | ||
source_dir, | ||
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
) | ||
|
||
expected_files = {"package.json", "included.js"} | ||
output_files = set(os.listdir(self.artifacts_dir)) | ||
self.assertEqual(expected_files, output_files) | ||
|
||
def test_builds_project_with_remote_dependencies(self): | ||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_builds_project_with_remote_dependencies(self, runtime): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps") | ||
|
||
self.builder.build( | ||
source_dir, | ||
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
) | ||
|
||
expected_files = {"package.json", "included.js", "node_modules"} | ||
|
@@ -102,15 +105,16 @@ def test_builds_project_with_remote_dependencies(self): | |
output_modules = set(os.listdir(os.path.join(self.artifacts_dir, "node_modules"))) | ||
self.assertEqual(expected_modules, output_modules) | ||
|
||
def test_builds_project_with_npmrc(self): | ||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_builds_project_with_npmrc(self, runtime): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npmrc") | ||
|
||
self.builder.build( | ||
source_dir, | ||
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
) | ||
|
||
expected_files = {"package.json", "included.js", "node_modules"} | ||
|
@@ -122,8 +126,20 @@ def test_builds_project_with_npmrc(self): | |
output_modules = set(os.listdir(os.path.join(self.artifacts_dir, "node_modules"))) | ||
self.assertEqual(expected_modules, output_modules) | ||
|
||
@parameterized.expand(["package-lock", "shrinkwrap", "package-lock-and-shrinkwrap"]) | ||
def test_builds_project_with_lockfile(self, dir_name): | ||
@parameterized.expand( | ||
[ | ||
("nodejs12.x", "package-lock"), | ||
("nodejs14.x", "package-lock"), | ||
("nodejs16.x", "package-lock"), | ||
("nodejs12.x", "shrinkwrap"), | ||
("nodejs14.x", "shrinkwrap"), | ||
("nodejs16.x", "shrinkwrap"), | ||
("nodejs12.x", "package-lock-and-shrinkwrap"), | ||
("nodejs14.x", "package-lock-and-shrinkwrap"), | ||
("nodejs16.x", "package-lock-and-shrinkwrap"), | ||
] | ||
) | ||
def test_builds_project_with_lockfile(self, runtime, dir_name): | ||
expected_files_common = {"package.json", "included.js", "node_modules"} | ||
expected_files_by_dir_name = { | ||
"package-lock": {"package-lock.json"}, | ||
|
@@ -138,7 +154,7 @@ def test_builds_project_with_lockfile(self, dir_name): | |
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
) | ||
|
||
expected_files = expected_files_common.union(expected_files_by_dir_name[dir_name]) | ||
|
@@ -147,8 +163,8 @@ def test_builds_project_with_lockfile(self, dir_name): | |
|
||
self.assertEqual(expected_files, output_files) | ||
|
||
def test_fails_if_npm_cannot_resolve_dependencies(self): | ||
|
||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_fails_if_npm_cannot_resolve_dependencies(self, runtime): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "broken-deps") | ||
|
||
with self.assertRaises(WorkflowFailedError) as ctx: | ||
|
@@ -157,20 +173,21 @@ def test_fails_if_npm_cannot_resolve_dependencies(self): | |
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
) | ||
|
||
self.assertIn("No matching version found for [email protected]", str(ctx.exception)) | ||
|
||
def test_builds_project_with_remote_dependencies_without_download_dependencies_with_dependencies_dir(self): | ||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_builds_project_with_remote_dependencies_without_download_dependencies_with_dependencies_dir(self, runtime): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps") | ||
|
||
self.builder.build( | ||
source_dir, | ||
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
dependencies_dir=self.dependencies_dir, | ||
download_dependencies=False, | ||
) | ||
|
@@ -179,15 +196,16 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w | |
output_files = set(os.listdir(self.artifacts_dir)) | ||
self.assertEqual(expected_files, output_files) | ||
|
||
def test_builds_project_with_remote_dependencies_with_download_dependencies_and_dependencies_dir(self): | ||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_builds_project_with_remote_dependencies_with_download_dependencies_and_dependencies_dir(self, runtime): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps") | ||
|
||
self.builder.build( | ||
source_dir, | ||
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
dependencies_dir=self.dependencies_dir, | ||
download_dependencies=True, | ||
) | ||
|
@@ -208,7 +226,10 @@ def test_builds_project_with_remote_dependencies_with_download_dependencies_and_ | |
output_dependencies_files = set(os.listdir(os.path.join(self.dependencies_dir))) | ||
self.assertNotIn(expected_dependencies_files, output_dependencies_files) | ||
|
||
def test_builds_project_with_remote_dependencies_without_download_dependencies_without_dependencies_dir(self): | ||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_builds_project_with_remote_dependencies_without_download_dependencies_without_dependencies_dir( | ||
self, runtime | ||
): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps") | ||
|
||
with mock.patch.object(logger, "info") as mock_info: | ||
|
@@ -217,7 +238,7 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w | |
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
dependencies_dir=None, | ||
download_dependencies=False, | ||
) | ||
|
@@ -231,15 +252,16 @@ def test_builds_project_with_remote_dependencies_without_download_dependencies_w | |
"artifacts directory. " | ||
) | ||
|
||
def test_builds_project_without_combine_dependencies(self): | ||
@parameterized.expand([("nodejs12.x",), ("nodejs14.x",), ("nodejs16.x",)]) | ||
def test_builds_project_without_combine_dependencies(self, runtime): | ||
source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps") | ||
|
||
self.builder.build( | ||
source_dir, | ||
self.artifacts_dir, | ||
self.scratch_dir, | ||
os.path.join(source_dir, "package.json"), | ||
runtime=self.runtime, | ||
runtime=runtime, | ||
dependencies_dir=self.dependencies_dir, | ||
download_dependencies=True, | ||
combine_dependencies=False, | ||
|
Oops, something went wrong.