|
5 | 5 | from unittest import TestCase, main
|
6 | 6 | from pathlib import Path
|
7 | 7 | import time
|
8 |
| - |
| 8 | +import os |
9 | 9 | import requests
|
| 10 | +from contextlib import contextmanager |
10 | 11 | from parameterized import parameterized
|
11 | 12 |
|
12 |
| -SLEEP_TIME = 2 |
| 13 | +SLEEP_TIME = 1.5 |
13 | 14 | DEFAULT_1P_ENTRYPOINT = "/lambda-entrypoint.sh"
|
14 | 15 | ARCHS = ["x86_64", "arm64", ""]
|
15 | 16 |
|
16 | 17 |
|
| 18 | + |
17 | 19 | class TestEndToEnd(TestCase):
|
| 20 | + ARCH = os.environ.get('TEST_ARCH', "") |
| 21 | + PORT = os.environ.get('TEST_PORT', 8002) |
18 | 22 | @classmethod
|
19 | 23 | def setUpClass(cls):
|
20 | 24 | testdata_path = Path(__file__).resolve().parents[1].joinpath("testdata")
|
21 | 25 | dockerfile_path = testdata_path.joinpath("Dockerfile-allinone")
|
22 |
| - cls.image_name = "aws-lambda-local:testing" |
23 | 26 | cls.path_to_binary = Path().resolve().joinpath("bin")
|
24 | 27 |
|
25 | 28 | # build image
|
26 |
| - for arch in ARCHS: |
27 |
| - image_name = cls.image_name if arch == "" else f"{cls.image_name}-{arch}" |
28 |
| - architecture = arch if arch == "arm64" else "amd64" |
29 |
| - build_cmd = [ |
30 |
| - "docker", |
31 |
| - "build", |
32 |
| - "--platform", |
33 |
| - f"linux/{architecture}", |
34 |
| - "-t", |
35 |
| - image_name, |
36 |
| - "-f", |
37 |
| - str(dockerfile_path), |
38 |
| - str(testdata_path), |
39 |
| - ] |
40 |
| - Popen(build_cmd).communicate() |
| 29 | + image_name_base = "aws-lambda-local:testing" |
| 30 | + cls.image_name = image_name_base if cls.ARCH == "" else f"{image_name_base}-{cls.ARCH}" |
| 31 | + architecture = cls.ARCH if cls.ARCH == "arm64" else "amd64" |
| 32 | + docker_arch = cls.ARCH if cls.ARCH == "arm64" else "x86_64" |
| 33 | + |
| 34 | + build_cmd = [ |
| 35 | + "docker", |
| 36 | + "build", |
| 37 | + "--platform", |
| 38 | + f"linux/{architecture}", |
| 39 | + "-t", |
| 40 | + cls.image_name, |
| 41 | + "-f", |
| 42 | + str(dockerfile_path), |
| 43 | + str(testdata_path), |
| 44 | + "--build-arg", |
| 45 | + f"IMAGE_ARCH={docker_arch}", |
| 46 | + ] |
| 47 | + Popen(build_cmd).communicate() |
41 | 48 |
|
42 | 49 | @classmethod
|
43 | 50 | def tearDownClass(cls):
|
44 |
| - images_to_delete = [ |
45 |
| - "envvarcheck", |
46 |
| - "twoinvokes", |
47 |
| - "arnexists", |
48 |
| - "customname", |
49 |
| - "timeout", |
50 |
| - "exception", |
51 |
| - "remaining_time_in_three_seconds", |
52 |
| - "remaining_time_in_ten_seconds", |
53 |
| - "remaining_time_in_default_deadline", |
54 |
| - "pre-runtime-api", |
55 |
| - "assert-overwritten", |
56 |
| - "port_override" |
57 |
| - ] |
58 |
| - |
59 |
| - for image in images_to_delete: |
60 |
| - for arch in ARCHS: |
61 |
| - arch_tag = "" if arch == "" else f"-{arch}" |
62 |
| - cmd = f"docker rm -f {image}{arch_tag}" |
63 |
| - Popen(cmd.split(" ")).communicate() |
64 |
| - |
65 |
| - for arch in ARCHS: |
66 |
| - arch_tag = "" if arch == "" else f"-{arch}" |
67 |
| - Popen(f"docker rmi {cls.image_name}{arch_tag}".split(" ")).communicate() |
| 51 | + Popen(f"docker rmi {cls.image_name}".split(" ")).communicate() |
68 | 52 |
|
69 |
| - def tagged_name(self, name, architecture): |
70 |
| - tag = self.get_tag(architecture) |
71 |
| - return (name + tag, "aws-lambda-rie" + tag, self.image_name + tag) |
| 53 | + def tagged_name(self, name): |
| 54 | + tag = self.get_tag() |
| 55 | + return (name + tag, "aws-lambda-rie" + tag, self.image_name) |
72 | 56 |
|
73 |
| - def get_tag(self, architecture): |
74 |
| - return "" if architecture == "" else str(f"-{architecture}") |
| 57 | + def get_tag(self): |
| 58 | + return "" if self.ARCH == "" else str(f"-{self.ARCH}") |
75 | 59 |
|
76 | 60 | def run_command(self, cmd):
|
77 | 61 | Popen(cmd.split(" ")).communicate()
|
78 | 62 |
|
79 | 63 | def sleep_1s(self):
|
80 | 64 | time.sleep(SLEEP_TIME)
|
81 | 65 |
|
82 |
| - def invoke_function(self, port): |
| 66 | + def invoke_function(self): |
83 | 67 | return requests.post(
|
84 |
| - f"http://localhost:{port}/2015-03-31/functions/function/invocations", json={} |
| 68 | + f"http://localhost:{self.PORT}/2015-03-31/functions/function/invocations", json={} |
85 | 69 | )
|
86 | 70 |
|
87 |
| - def create_container_and_invoke_function(self, cmd, port): |
88 |
| - self.run_command(cmd) |
| 71 | + @contextmanager |
| 72 | + def create_container(self, param, image): |
| 73 | + try: |
| 74 | + platform = "x86_64" if self.ARCH == "" else self.ARCH |
| 75 | + cmd_full = f"docker run --platform linux/{platform} {param}" |
| 76 | + self.run_command(cmd_full) |
89 | 77 |
|
90 |
| - # sleep 1s to give enough time for the endpoint to be up to curl |
91 |
| - self.sleep_1s() |
| 78 | + # sleep 1s to give enough time for the endpoint to be up to curl |
| 79 | + self.sleep_1s() |
| 80 | + yield |
| 81 | + except Exception as e: |
| 82 | + print(f"An error occurred while executing cmd: {cmd_full}. error: {e}") |
| 83 | + raise e |
| 84 | + finally: |
| 85 | + self.run_command(f"docker stop {image}") |
| 86 | + self.run_command(f"docker rm -f {image}") |
92 | 87 |
|
93 |
| - return self.invoke_function(port) |
94 | 88 |
|
95 |
| - @parameterized.expand([("x86_64", "8000"), ("arm64", "9000"), ("", "9050")]) |
96 |
| - def test_env_var_with_equal_sign(self, arch, port): |
97 |
| - image, rie, image_name = self.tagged_name("envvarcheck", arch) |
98 |
| - |
99 |
| - cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_env_var_handler" |
| 89 | + def test_env_var_with_equal_sign(self): |
| 90 | + image, rie, image_name = self.tagged_name("envvarcheck") |
| 91 | + params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_env_var_handler" |
100 | 92 |
|
101 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 93 | + with self.create_container(params, image): |
| 94 | + r = self.invoke_function() |
102 | 95 |
|
103 |
| - self.assertEqual(b'"4=4"', r.content) |
| 96 | + self.assertEqual(b'"4=4"', r.content) |
104 | 97 |
|
105 |
| - @parameterized.expand([("x86_64", "8001"), ("arm64", "9001"), ("", "9051")]) |
106 |
| - def test_two_invokes(self, arch, port): |
107 |
| - image, rie, image_name = self.tagged_name("twoinvokes", arch) |
108 | 98 |
|
109 |
| - cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler" |
| 99 | + def test_two_invokes(self): |
| 100 | + image, rie, image_name = self.tagged_name("twoinvokes") |
110 | 101 |
|
111 |
| - r = self.create_container_and_invoke_function(cmd, port) |
112 |
| - |
113 |
| - self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 102 | + params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler" |
114 | 103 |
|
115 |
| - # Make sure we can invoke the function twice |
116 |
| - r = self.invoke_function(port) |
| 104 | + with self.create_container(params, image): |
| 105 | + r = self.invoke_function() |
117 | 106 |
|
118 |
| - self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 107 | + self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 108 | + |
| 109 | + # Make sure we can invoke the function twice |
| 110 | + r = self.invoke_function() |
| 111 | + |
| 112 | + self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 113 | + |
119 | 114 |
|
120 |
| - @parameterized.expand([("x86_64", "8002"), ("arm64", "9002"), ("", "9052")]) |
121 |
| - def test_lambda_function_arn_exists(self, arch, port): |
122 |
| - image, rie, image_name = self.tagged_name("arnexists", arch) |
| 115 | + def test_lambda_function_arn_exists(self): |
| 116 | + image, rie, image_name = self.tagged_name("arnexists") |
123 | 117 |
|
124 |
| - cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context" |
| 118 | + params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context" |
125 | 119 |
|
126 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 120 | + with self.create_container(params, image): |
| 121 | + r = self.invoke_function() |
127 | 122 |
|
128 |
| - self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 123 | + self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 124 | + |
129 | 125 |
|
130 |
| - @parameterized.expand([("x86_64", "8003"), ("arm64", "9003"), ("", "9053")]) |
131 |
| - def test_lambda_function_arn_exists_with_defining_custom_name(self, arch, port): |
132 |
| - image, rie, image_name = self.tagged_name("customname", arch) |
| 126 | + def test_lambda_function_arn_exists_with_defining_custom_name(self): |
| 127 | + image, rie, image_name = self.tagged_name("customname") |
133 | 128 |
|
134 |
| - cmd = f"docker run --name {image} --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context" |
| 129 | + params = f"--name {image} --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context" |
135 | 130 |
|
136 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 131 | + with self.create_container(params, image): |
| 132 | + r = self.invoke_function() |
137 | 133 |
|
138 |
| - self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 134 | + self.assertEqual(b'"My lambda ran succesfully"', r.content) |
139 | 135 |
|
140 |
| - @parameterized.expand([("x86_64", "8004"), ("arm64", "9004"), ("", "9054")]) |
141 |
| - def test_timeout_invoke(self, arch, port): |
142 |
| - image, rie, image_name = self.tagged_name("timeout", arch) |
143 | 136 |
|
144 |
| - cmd = f"docker run --name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.sleep_handler" |
| 137 | + def test_timeout_invoke(self): |
| 138 | + image, rie, image_name = self.tagged_name("timeout") |
145 | 139 |
|
146 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 140 | + params = f"--name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.sleep_handler" |
| 141 | + |
| 142 | + with self.create_container(params, image): |
| 143 | + r = self.invoke_function() |
147 | 144 |
|
148 |
| - self.assertEqual(b"Task timed out after 1.00 seconds", r.content) |
| 145 | + self.assertEqual(b"Task timed out after 1.00 seconds", r.content) |
149 | 146 |
|
150 |
| - @parameterized.expand([("x86_64", "8005"), ("arm64", "9005"), ("", "9055")]) |
151 |
| - def test_exception_returned(self, arch, port): |
152 |
| - image, rie, image_name = self.tagged_name("exception", arch) |
153 | 147 |
|
154 |
| - cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.exception_handler" |
| 148 | + def test_exception_returned(self): |
| 149 | + image, rie, image_name = self.tagged_name("exception") |
| 150 | + |
| 151 | + params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.exception_handler" |
| 152 | + |
| 153 | + with self.create_container(params, image): |
| 154 | + r = self.invoke_function() |
| 155 | + |
| 156 | + # Except the 3 fields assrted below, there's another field `request_id` included start from python3.12 runtime. |
| 157 | + # We should ignore asserting the field `request_id` for it is in a UUID like format and changes everytime |
| 158 | + result = r.json() |
| 159 | + self.assertEqual(result["errorMessage"], "Raising an exception") |
| 160 | + self.assertEqual(result["errorType"], "Exception") |
| 161 | + self.assertEqual(result["stackTrace"], [" File \"/var/task/main.py\", line 13, in exception_handler\n raise Exception(\"Raising an exception\")\n"]) |
155 | 162 |
|
156 |
| - r = self.create_container_and_invoke_function(cmd, port) |
157 |
| - |
158 |
| - self.assertEqual( |
159 |
| - 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"]}', |
160 |
| - r.content, |
161 |
| - ) |
162 | 163 |
|
163 |
| - @parameterized.expand([("x86_64", "8006"), ("arm64", "9006"), ("", "9056")]) |
164 |
| - def test_context_get_remaining_time_in_three_seconds(self, arch, port): |
165 |
| - image, rie, image_name = self.tagged_name("remaining_time_in_three_seconds", arch) |
| 164 | + def test_context_get_remaining_time_in_three_seconds(self): |
| 165 | + image, rie, image_name = self.tagged_name("remaining_time_in_three_seconds") |
166 | 166 |
|
167 |
| - cmd = f"docker run --name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=3 -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler" |
| 167 | + params = f"--name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=3 -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler" |
168 | 168 |
|
169 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 169 | + with self.create_container(params, image): |
| 170 | + r = self.invoke_function() |
170 | 171 |
|
171 |
| - # Execution time is not decided, 1.0s ~ 3.0s is a good estimation |
172 |
| - self.assertLess(int(r.content), 3000) |
173 |
| - self.assertGreater(int(r.content), 1000) |
| 172 | + # Execution time is not decided, 1.0s ~ 3.0s is a good estimation |
| 173 | + self.assertLess(int(r.content), 3000) |
| 174 | + self.assertGreater(int(r.content), 1000) |
174 | 175 |
|
175 |
| - @parameterized.expand([("x86_64", "8007"), ("arm64", "9007"), ("", "9057")]) |
176 |
| - def test_context_get_remaining_time_in_ten_seconds(self, arch, port): |
177 |
| - image, rie, image_name = self.tagged_name("remaining_time_in_ten_seconds", arch) |
178 | 176 |
|
179 |
| - cmd = f"docker run --name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=10 -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler" |
| 177 | + def test_context_get_remaining_time_in_ten_seconds(self): |
| 178 | + image, rie, image_name = self.tagged_name("remaining_time_in_ten_seconds") |
180 | 179 |
|
181 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 180 | + params = f"--name {image} -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=10 -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler" |
| 181 | + |
| 182 | + with self.create_container(params, image): |
| 183 | + r = self.invoke_function() |
182 | 184 |
|
183 |
| - # Execution time is not decided, 8.0s ~ 10.0s is a good estimation |
184 |
| - self.assertLess(int(r.content), 10000) |
185 |
| - self.assertGreater(int(r.content), 8000) |
| 185 | + # Execution time is not decided, 8.0s ~ 10.0s is a good estimation |
| 186 | + self.assertLess(int(r.content), 10000) |
| 187 | + self.assertGreater(int(r.content), 8000) |
| 188 | + |
| 189 | + |
| 190 | + def test_context_get_remaining_time_in_default_deadline(self): |
| 191 | + image, rie, image_name = self.tagged_name("remaining_time_in_default_deadline") |
186 | 192 |
|
187 |
| - @parameterized.expand([("x86_64", "8008"), ("arm64", "9008"), ("", "9058")]) |
188 |
| - def test_context_get_remaining_time_in_default_deadline(self, arch, port): |
189 |
| - image, rie, image_name = self.tagged_name("remaining_time_in_default_deadline", arch) |
| 193 | + params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler" |
190 | 194 |
|
191 |
| - cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler" |
| 195 | + with self.create_container(params, image): |
| 196 | + r = self.invoke_function() |
192 | 197 |
|
193 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 198 | + # Executation time is not decided, 298.0s ~ 300.0s is a good estimation |
| 199 | + self.assertLess(int(r.content), 300000) |
| 200 | + self.assertGreater(int(r.content), 298000) |
194 | 201 |
|
195 |
| - # Executation time is not decided, 298.0s ~ 300.0s is a good estimation |
196 |
| - self.assertLess(int(r.content), 300000) |
197 |
| - self.assertGreater(int(r.content), 298000) |
198 | 202 |
|
199 |
| - @parameterized.expand([("x86_64", "8009"), ("arm64", "9009"), ("", "9059")]) |
200 |
| - def test_invoke_with_pre_runtime_api_runtime(self, arch, port): |
201 |
| - image, rie, image_name = self.tagged_name("pre-runtime-api", arch) |
| 203 | + def test_invoke_with_pre_runtime_api_runtime(self): |
| 204 | + image, rie, image_name = self.tagged_name("pre-runtime-api") |
202 | 205 |
|
203 |
| - cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler" |
| 206 | + params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler" |
204 | 207 |
|
205 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 208 | + with self.create_container(params, image): |
| 209 | + r = self.invoke_function() |
206 | 210 |
|
207 |
| - self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 211 | + self.assertEqual(b'"My lambda ran succesfully"', r.content) |
208 | 212 |
|
209 |
| - @parameterized.expand([("x86_64", "8010"), ("arm64", "9010"), ("", "9060")]) |
210 |
| - def test_function_name_is_overriden(self, arch, port): |
211 |
| - image, rie, image_name = self.tagged_name("assert-overwritten", arch) |
212 | 213 |
|
213 |
| - cmd = f"docker run --name {image} -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_env_var_is_overwritten" |
| 214 | + def test_function_name_is_overriden(self): |
| 215 | + image, rie, image_name = self.tagged_name("assert-overwritten") |
214 | 216 |
|
215 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 217 | + params = f"--name {image} -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_env_var_is_overwritten" |
| 218 | + |
| 219 | + with self.create_container(params, image): |
| 220 | + r = self.invoke_function() |
216 | 221 |
|
217 |
| - self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 222 | + self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 223 | + |
218 | 224 |
|
219 |
| - @parameterized.expand([("x86_64", "8011"), ("arm64", "9011"), ("", "9061")]) |
220 |
| - def test_port_override(self, arch, port): |
221 |
| - image, rie, image_name = self.tagged_name("port_override", arch) |
| 225 | + def test_port_override(self): |
| 226 | + image, rie, image_name = self.tagged_name("port_override") |
222 | 227 |
|
223 | 228 | # Use port 8081 inside the container instead of 8080
|
224 |
| - cmd = f"docker run --name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {port}:8081 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler --runtime-interface-emulator-address 0.0.0.0:8081" |
| 229 | + params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8081 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler --runtime-interface-emulator-address 0.0.0.0:8081" |
225 | 230 |
|
226 |
| - r = self.create_container_and_invoke_function(cmd, port) |
| 231 | + with self.create_container(params, image): |
| 232 | + r = self.invoke_function() |
227 | 233 |
|
228 |
| - self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 234 | + self.assertEqual(b'"My lambda ran succesfully"', r.content) |
| 235 | + |
229 | 236 |
|
230 | 237 |
|
231 | 238 | if __name__ == "__main__":
|
|
0 commit comments