Skip to content

Commit

Permalink
Add integ tests and remove &511 permission mod
Browse files Browse the repository at this point in the history
  • Loading branch information
jfuss committed Apr 15, 2020
1 parent a4a77c5 commit f796a57
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
12 changes: 8 additions & 4 deletions samcli/local/lambdafn/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ def unzip(zip_file_path, output_dir, permission=None):
# For each item in the zip file, extract the file and set permissions if available
for file_info in zip_ref.infolist():
extracted_path = _extract(file_info, output_dir, zip_ref)
_set_permissions(file_info, extracted_path)

_override_permissions(extracted_path, permission)
# If the extracted_path is a symlink, do not set the permissions. If the target of the symlink does not
# exist, then os.chmod will fail with FileNotFoundError
if not os.path.islink(extracted_path):
_set_permissions(file_info, extracted_path)
_override_permissions(extracted_path, permission)

_override_permissions(output_dir, permission)
if not os.path.islink(extracted_path):
_override_permissions(output_dir, permission)


def _override_permissions(path, permission):
Expand Down Expand Up @@ -138,7 +142,7 @@ def _set_permissions(zip_file_info, extracted_path):
"""

# Permission information is stored in first two bytes.
permission = (zip_file_info.external_attr >> 16) & 511
permission = zip_file_info.external_attr >> 16
if not permission:
# Zips created on certain Windows machines, however, might not have any permission information on them.
# Skip setting a permission on these files.
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/local/invoke/test_integrations_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,23 @@ def test_skip_pull_image_in_env_var(self):
process_stderr = stderr.strip()
self.assertIn("Requested to skip pulling images", process_stderr.decode("utf-8"))

@skipIf(SKIP_LAYERS_TESTS, "Skip layers tests in Appveyor only")
@pytest.mark.flaky(reruns=3)
def test_invoke_returns_execpted_results_from_git_function(self):
command_list = self.get_command_list(
"GitLayerFunction", template_path=self.template_path, event_path=self.event_path
)

process = Popen(command_list, stdout=PIPE)
try:
stdout, _ = process.communicate(timeout=TIMEOUT)
except TimeoutExpired:
process.kill()
raise

process_stdout = stdout.strip()
self.assertEqual(process_stdout.decode("utf-8"), '"git init passed"')


class TestUsingConfigFiles(InvokeIntegBase):
template = Path("template.yml")
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/testdata/invoke/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
import os
import sys
import subprocess

print ("Loading function")

Expand Down Expand Up @@ -46,3 +47,10 @@ def echo_event(event, context):

def raise_exception(event, context):
raise Exception("Lambda is raising an exception")


def execute_git(event, context):
return_code = subprocess.call(['git', 'init', '/tmp/samtesting'])
assert return_code == 0

return "git init passed"
9 changes: 9 additions & 0 deletions tests/integration/testdata/invoke/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,12 @@ Resources:
Handler: main.echo_event
Runtime: python3.6
CodeUri: .

GitLayerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: main.execute_git
Runtime: python3.8
Layers:
- arn:aws:lambda:us-east-1:553035198032:layer:git-lambda2:5
2 changes: 1 addition & 1 deletion tests/unit/local/lambdafn/test_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _verify_external_attributes(self, actual_permissions, expected_permission, k
self.actual_symlinks += 1
return

self.assertEquals(
self.assertEqual(
expected_permission,
actual_permissions,
"File {} has wrong permission {}, expected {}.".format(key, actual_permissions, expected_permission),
Expand Down

0 comments on commit f796a57

Please sign in to comment.