-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[WIP] White-list nodejs for aws-lambda-builders #845
Changes from all commits
1d04f9d
3e8df36
a3b4f22
a5efdc1
39274a1
4cd6523
60a6c38
804e571
14ba361
216fc4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ Resources: | |
HelloWorldFunction: | ||
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction | ||
Properties: | ||
CodeUri: hello_world/ | ||
CodeUri: hello-world/ | ||
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. just curious: any reason for the change in the name? 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. Conversations with people familiar with Node.js said dashes are used not underscores. So I changed this to make it match what the community is doing/the Node.js style |
||
Handler: app.lambdaHandler | ||
{%- if cookiecutter.runtime == 'nodejs6.10' %} | ||
Runtime: nodejs6.10 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ class TestBuildCommand_PythonFunctions(BuildIntegBase): | |
"jinja2", | ||
'requirements.txt'} | ||
|
||
FUNCTION_LOGICAL_ID = "PythonFunction" | ||
FUNCTION_LOGICAL_ID = "Function" | ||
|
||
@parameterized.expand([ | ||
("python2.7", False), | ||
|
@@ -37,7 +37,7 @@ def test_with_default_requirements(self, runtime, use_container): | |
self.skipTest("Current Python version '{}' does not match Lambda runtime version '{}'".format(py_version, | ||
runtime)) | ||
|
||
overrides = {"PythonRuntime": runtime} | ||
overrides = {"Runtime": runtime, "CodeUri": "Python"} | ||
cmdlist = self.get_command_list(use_container=use_container, | ||
parameter_overrides=overrides) | ||
|
||
|
@@ -113,7 +113,7 @@ def _get_python_version(self): | |
class TestBuildCommand_ErrorCases(BuildIntegBase): | ||
|
||
def test_unsupported_runtime(self): | ||
overrides = {"PythonRuntime": "unsupportedpython"} | ||
overrides = {"Runtime": "unsupportedpython", "CodeUri": "NoThere"} | ||
cmdlist = self.get_command_list(parameter_overrides=overrides) | ||
|
||
LOG.info("Running Command: {}", cmdlist) | ||
|
@@ -124,3 +124,71 @@ def test_unsupported_runtime(self): | |
self.assertEquals(1, process.returncode) | ||
|
||
self.assertIn("Build Failed", process_stdout) | ||
|
||
|
||
class TestBuildCommand_NodeFunctions(BuildIntegBase): | ||
|
||
EXPECTED_FILES_GLOBAL_MANIFEST = set() | ||
EXPECTED_FILES_PROJECT_MANIFEST = {'node_modules', 'main.js'} | ||
EXPECTED_NODE_MODULES = {'minimal-request-promise'} | ||
|
||
FUNCTION_LOGICAL_ID = "Function" | ||
|
||
@parameterized.expand([ | ||
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. Brilliant! thanks for adding all cases! |
||
("nodejs4.3", False), | ||
("nodejs6.10", False), | ||
("nodejs8.10", False), | ||
("nodejs4.3", "use_container"), | ||
("nodejs6.10", "use_container"), | ||
("nodejs8.10", "use_container") | ||
]) | ||
def test_with_default_package_json(self, runtime, use_container): | ||
overrides = {"Runtime": runtime, "CodeUri": "Node"} | ||
cmdlist = self.get_command_list(use_container=use_container, | ||
parameter_overrides=overrides) | ||
|
||
LOG.info("Running Command: {}", cmdlist) | ||
process = subprocess.Popen(cmdlist, cwd=self.working_dir) | ||
process.wait() | ||
|
||
self._verify_built_artifact(self.default_build_dir, self.FUNCTION_LOGICAL_ID, | ||
self.EXPECTED_FILES_PROJECT_MANIFEST, self.EXPECTED_NODE_MODULES) | ||
|
||
self._verify_resource_property(str(self.built_template), | ||
"OtherRelativePathResource", | ||
"BodyS3Location", | ||
os.path.relpath( | ||
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. Thats a lotta path heh. 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. Mostly stolen from the python above. |
||
os.path.normpath(os.path.join(str(self.test_data_path), "SomeRelativePath")), | ||
str(self.default_build_dir)) | ||
) | ||
|
||
def _verify_built_artifact(self, build_dir, function_logical_id, expected_files, expected_modules): | ||
|
||
self.assertTrue(build_dir.exists(), "Build directory should be created") | ||
|
||
build_dir_files = os.listdir(str(build_dir)) | ||
self.assertIn("template.yaml", build_dir_files) | ||
self.assertIn(function_logical_id, build_dir_files) | ||
|
||
template_path = build_dir.joinpath("template.yaml") | ||
resource_artifact_dir = build_dir.joinpath(function_logical_id) | ||
|
||
# Make sure the template has correct CodeUri for resource | ||
self._verify_resource_property(str(template_path), | ||
function_logical_id, | ||
"CodeUri", | ||
function_logical_id) | ||
|
||
all_artifacts = set(os.listdir(str(resource_artifact_dir))) | ||
actual_files = all_artifacts.intersection(expected_files) | ||
self.assertEquals(actual_files, expected_files) | ||
|
||
all_modules = set(os.listdir(str(resource_artifact_dir.joinpath('node_modules')))) | ||
actual_files = all_modules.intersection(expected_modules) | ||
self.assertEquals(actual_files, expected_modules) | ||
|
||
def _verify_resource_property(self, template_path, logical_id, property, expected_value): | ||
|
||
with open(template_path, 'r') as fp: | ||
template_dict = yaml_parse(fp.read()) | ||
self.assertEquals(expected_value, template_dict["Resources"][logical_id]["Properties"][property]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "npmdeps", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"author": "", | ||
"license": "APACHE2.0", | ||
"dependencies": { | ||
"minimal-request-promise": "*" | ||
} | ||
} |
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.
Noo, lets not do if else's again, this might become like our entrypoint file. Given that there may be more runtimes that we support building.
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.
What is your suggestion then?
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.
Suggestion is to be encapsulate in a dictionary, and invoke corresponding actions based on a match. But I will not block on this. we can address this separately, I'll create an issue.