-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test with msi * fix path * set quite option * wait for installation to finish and refresh env * use Start-Process * only install dev deps * update path after installation * run pip install with SAM_CLI_DEV * check sam with powershell * set path before starting pytest * add shell=True for all subprocess calls * chore: Update CFN Lint version to support python 3.11 (#5651) * Update CFN Lint version to support python 3.11 * Run make update-reproducible-reqs --------- Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> * fix: Require file label to run before maintainers (#5656) * Require file label to run before maintainers * Run maintainer label job even if previous job fails * Add Windows config * Fix formatting * Update config * test * Update config * Update config * Update config * Update config * chore: update aws_lambda_builders to 1.36.0 (#5655) Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> * Update config * Update config * fix(invoke): Write in UTF-8 string instead of bytes (#5642) * Revert "fix: Revert UTF-8 fixes #5485 and #5427 (#5512)" This reverts commit 36f8bf9. * Enforce utf8 on stdout/stderr/logfile --------- Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com> * chore(deps): bump cryptography from 41.0.2 to 41.0.3 in /requirements (#5675) Bumps [cryptography](https://github.com/pyca/cryptography) from 41.0.2 to 41.0.3. - [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst) - [Commits](pyca/cryptography@41.0.2...41.0.3) --- updated-dependencies: - dependency-name: cryptography dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add linux config * fix(test): Force reading file with utf8 in tests for windows (#5679) Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com> * fix(test): Increase max execution time for timeout tests (#5680) Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com> * Update install links * Update linux config * Update linux config * Update linux config * Update linux config * Update linux config * Update linux config * Update linux config * Update linux config * Update linux config * Update linux config * Update linux config * Update Windows config * Update Windows config * Update Windows config * Update Windows config * Update Windows config * Update Windows config --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Co-authored-by: Connor Kirkpatrick <connor.kirkpatrick@hotmail.com> Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> Co-authored-by: Lucas <12496191+lucashuy@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com> Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7943548
commit 8a9e0c9
Showing
23 changed files
with
291 additions
and
129 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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
from unittest import TestCase | ||
from subprocess import Popen, PIPE | ||
import os | ||
import random | ||
from pathlib import Path | ||
import threading | ||
|
||
import pytest | ||
import requests | ||
from parameterized import parameterized_class, parameterized | ||
|
||
from tests.testing_utils import run_command, start_persistent_process, read_until_string, kill_process | ||
|
||
|
||
@parameterized_class( | ||
("cdk_project_path", "cdk_version", "cdk_stack_template"), | ||
[ | ||
("/testdata/cdk_v1/typescript", "1.x", "TestStack.template.json"), | ||
("/testdata/cdk_v2/typescript", "2.x", "TestStack.template.json"), | ||
("/testdata/cdk_v1/python", "1.x", "TestStack.template.json"), | ||
("/testdata/cdk_v2/python", "2.x", "TestStack.template.json"), | ||
("/testdata/cdk_v1/java", "1.x", "TestStack.template.json"), | ||
("/testdata/cdk_v2/java", "2.x", "TestStack.template.json"), | ||
], | ||
) | ||
class TestSamCdkIntegration(TestCase): | ||
integration_dir = str(Path(__file__).resolve().parents[0]) | ||
cdk_project_path = "" | ||
cdk_version = "" | ||
cdk_stack_template = "" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.cdk_project = cls.integration_dir + cls.cdk_project_path | ||
cls.api_port = str(TestSamCdkIntegration.random_port()) | ||
cls.build_cdk_project() | ||
cls.build() | ||
|
||
cls.start_api() | ||
cls.url = "http://127.0.0.1:{}".format(cls.api_port) | ||
|
||
@classmethod | ||
def build_cdk_project(cls): | ||
command_list = ["npx", f"aws-cdk@{cls.cdk_version}", "synth", "--no-staging"] | ||
working_dir = cls.cdk_project | ||
result = run_command(command_list, cwd=working_dir) | ||
if result.process.returncode != 0: | ||
raise Exception("cdk synth command failed") | ||
|
||
@classmethod | ||
def build(cls): | ||
command = "sam" | ||
if os.getenv("SAM_CLI_DEV"): | ||
command = "samdev" | ||
command_list = [command, "build", "-t", cls.cdk_stack_template] | ||
working_dir = cls.cdk_project + "/cdk.out" | ||
result = run_command(command_list, cwd=working_dir) | ||
if result.process.returncode != 0: | ||
raise Exception("sam build command failed") | ||
|
||
@classmethod | ||
def start_api(cls): | ||
command = "sam" | ||
if os.getenv("SAM_CLI_DEV"): | ||
command = "samdev" | ||
|
||
command_list = [command, "local", "start-api", "-p", cls.api_port] | ||
|
||
working_dir = cls.cdk_project + "/cdk.out" | ||
cls.start_api_process = Popen(command_list, cwd=working_dir, stderr=PIPE, shell=True,) | ||
|
||
while True: | ||
line = cls.start_api_process.stderr.readline() | ||
if "Press CTRL+C to quit" in str(line): | ||
break | ||
|
||
cls.stop_api_reading_thread = False | ||
|
||
def read_sub_process_stderr(): | ||
while not cls.stop_api_reading_thread: | ||
cls.start_api_process.stderr.readline() | ||
|
||
cls.api_read_threading = threading.Thread(target=read_sub_process_stderr, daemon=True) | ||
cls.api_read_threading.start() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
# After all the tests run, we need to kill the start_lambda process. | ||
cls.stop_api_reading_thread = True | ||
kill_process(cls.start_api_process) | ||
|
||
@staticmethod | ||
def random_port(): | ||
return random.randint(30000, 40000) | ||
|
||
@parameterized.expand( | ||
[ | ||
("/httpapis/nestedPythonFunction", "Hello World from Nested Python Function Construct 7"), | ||
("/restapis/spec/pythonFunction", "Hello World from python function construct 7"), | ||
("/restapis/normal/pythonFunction", "Hello World from python function construct 7"), | ||
("/restapis/normal/functionPythonRuntime", "Hello World from function construct with python runtime 7"), | ||
("/restapis/normal/preBuiltFunctionPythonRuntime", "Hello World from python pre built function 7"), | ||
( | ||
"/restapis/normal/bundledFunctionPythonRuntime", | ||
"Hello World from bundled function construct with python runtime 7", | ||
), | ||
("/restapis/normal/nodejsFunction", "Hello World from nodejs function construct 7"), | ||
("/restapis/normal/functionNodeJsRuntime", "Hello World from function construct with nodejs runtime 7"), | ||
("/restapis/normal/preBuiltFunctionNodeJsRuntime", "Hello World from nodejs pre built function 7"), | ||
("/restapis/normal/goFunction", "Hello World from go function construct"), | ||
("/restapis/normal/functionGoRuntime", "Hello World from function construct with go runtime"), | ||
("/restapis/normal/dockerImageFunction", "Hello World from docker image function construct"), | ||
("/restapis/normal/functionImageAsset", "Hello World from function construct with image asset"), | ||
( | ||
"/restapis/normal/dockerImageFunctionWithSharedCode", | ||
"Hello World from docker image function construct " | ||
"with a Dockerfile that shares code with another Dockerfile", | ||
), | ||
( | ||
"/restapis/normal/functionImageAssetWithSharedCode", | ||
"Hello World from function construct with image asset " | ||
"with a Dockerfile that shares code with another Dockerfile", | ||
), | ||
] | ||
) | ||
@pytest.mark.flaky(reruns=3) | ||
@pytest.mark.timeout(timeout=1000, method="thread") | ||
def test_invoke_api(self, url_suffix, expected_message): | ||
response = requests.get(self.url + url_suffix, timeout=800) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json().get("message"), expected_message) |
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
Oops, something went wrong.