Skip to content

Fix integ tests #4

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 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions test/integration/local_lambda/end-to-end-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import requests

SLEEP_TIME = 2
DEFUALT_1P_ENTRYPOINT = "/lambda-entrypoint.sh"

class TestEndToEnd(TestCase):

@classmethod
Expand All @@ -33,23 +36,23 @@ def tearDownClass(cls):


def test_env_var_with_eqaul_sign(self):
cmd = f"docker run --name envvarcheck -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9003:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} /bootstrap-with-handler main.check_env_var_handler"
cmd = f"docker run --name envvarcheck -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9003:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFUALT_1P_ENTRYPOINT} main.check_env_var_handler"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(1)
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9003/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"4=4"', r.content)

def test_two_invokes(self):
cmd = f"docker run --name testing -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} /bootstrap-with-handler main.success_handler"
cmd = f"docker run --name testing -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFUALT_1P_ENTRYPOINT} main.success_handler"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(1)
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9000/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"My lambda ran succesfully"', r.content)
Expand All @@ -60,23 +63,23 @@ def test_two_invokes(self):


def test_timeout_invoke(self):
cmd = f"docker run --name timeout -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v {self.path_to_binary}:/local-lambda-runtime-server -p 9001:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} /bootstrap-with-handler main.sleep_handler"
cmd = f"docker run --name timeout -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v {self.path_to_binary}:/local-lambda-runtime-server -p 9001:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFUALT_1P_ENTRYPOINT} main.sleep_handler"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(1)
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9001/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b"Task timed out after 1.00 seconds", r.content)

def test_exception_returned(self):
cmd = f"docker run --name exception -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9002:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} /bootstrap-with-handler main.exception_handler"
cmd = f"docker run --name exception -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9002:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFUALT_1P_ENTRYPOINT} main.exception_handler"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(1)
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9002/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'{"errorMessage": "Raising an exception", "errorType": "Exception", "stackTrace": [" File \\"/var/task/main.py\\", line 13, in exception_handler\\n raise Exception(\\"Raising an exception\\")\\n"]}', r.content)
Expand Down Expand Up @@ -105,23 +108,23 @@ def tearDownClass(cls):
Popen(f"docker rmi {cls.image_name}".split(' ')).communicate()

def test_invoke_with_pre_runtime_api_runtime(self):
cmd = f"docker run --name testing -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} /bootstrap-with-handler main.success_handler"
cmd = f"docker run --name testing -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFUALT_1P_ENTRYPOINT} main.success_handler"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(1)
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9000/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"My lambda ran succesfully"', r.content)

def test_function_name_is_overriden(self):
cmd = f"docker run --name assert-overwritten -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v {self.path_to_binary}:/local-lambda-runtime-server -p 9009:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} /bootstrap-with-handler main.assert_env_var_is_overwritten"
cmd = f"docker run --name assert-overwritten -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v {self.path_to_binary}:/local-lambda-runtime-server -p 9009:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFUALT_1P_ENTRYPOINT} main.assert_env_var_is_overwritten"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(1)
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9009/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"My lambda ran succesfully"', r.content)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/testdata/Dockerfile-allinone
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.erc.aws/lambda/python:3.8
FROM public.ecr.aws/lambda/python:3.8

WORKDIR /var/task
COPY ./ ./
Expand Down
2 changes: 1 addition & 1 deletion test/integration/testdata/Dockerfile-python36
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.erc.aws/lambda/python:3.8
FROM public.ecr.aws/lambda/python:3.8

WORKDIR /var/task
COPY ./ ./
Expand Down