Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ integ-test:
func-test:
# Verify function test coverage only for `samcli.local` package
@echo Telemetry Status: $(SAM_CLI_TELEMETRY)
pytest --cov samcli.local --cov samcli.commands.local --cov-report term-missing tests/functional
pytest --cov samcli.local --cov samcli.commands.local --cov-report term-missing tests/functional/commands/validate tests/functional/commands/cli/test_global_config.py

smoke-test:
# Smoke tests run in parallel
Expand Down
6 changes: 6 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ for:
- "venv\\Scripts\\activate"
- "pytest --cov samcli --cov-report term-missing --cov-fail-under 95 tests/unit"
- "pylint --rcfile .pylintrc samcli"
# There are some functional tests that are currently broken due to not being updated with changed code or still running with node4.3 runtimes
# We need to update those but this allows us to at least runs the ones we currently have working
- "pytest tests/functional/commands/validate tests/functional/commands/cli/test_global_config.py"

# Runs only in Linux
- sh: "pytest -vv tests/integration"
Expand Down Expand Up @@ -88,6 +91,9 @@ for:
test_script:
- "pytest --cov samcli --cov-report term-missing --cov-fail-under 95 tests/unit"
- "pylint --rcfile .pylintrc samcli"
# There are some functional tests that are currently broken due to not being updated with changed code or still running with node4.3 runtimes
# We need to update those but this allows us to at least runs the ones we currently have working
- "pytest tests/functional/commands/validate tests/functional/commands/cli/test_global_config.py"

# Runs only in Linux
- sh: "pytest -vv tests/integration"
Expand Down
9 changes: 6 additions & 3 deletions tests/functional/commands/cli/test_global_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
import tempfile
import shutil
import os

from mock import mock_open, patch
from unittest import TestCase
from json import JSONDecodeError
from samcli.cli.global_config import GlobalConfig

try:
Expand All @@ -16,9 +16,12 @@
class TestGlobalConfig(TestCase):
def setUp(self):
self._cfg_dir = tempfile.mkdtemp()
self._previous_telemetry_environ = os.environ.get("SAM_CLI_TELEMETRY")
os.environ.pop("SAM_CLI_TELEMETRY")

def tearDown(self):
shutil.rmtree(self._cfg_dir)
os.environ["SAM_CLI_TELEMETRY"] = self._previous_telemetry_environ

def test_installation_id_with_side_effect(self):
gc = GlobalConfig(config_dir=self._cfg_dir)
Expand Down Expand Up @@ -91,7 +94,7 @@ def test_telemetry_flag_not_in_cfg(self):
def test_set_telemetry_flag_no_file(self):
path = Path(self._cfg_dir, "metadata.json")
gc = GlobalConfig(config_dir=self._cfg_dir)
self.assertIsNone(gc.telemetry_enabled) # pre-state test
self.assertFalse(gc.telemetry_enabled) # pre-state test
gc.telemetry_enabled = True
from_gc = gc.telemetry_enabled
json_body = json.loads(path.read_text())
Expand Down Expand Up @@ -135,7 +138,7 @@ def test_setter_raises_on_invalid_json(self):
with open(str(path), "w") as f:
f.write("NOT JSON, PROBABLY VALID YAML AM I RIGHT!?")
gc = GlobalConfig(config_dir=self._cfg_dir)
with self.assertRaises(JSONDecodeError):
with self.assertRaises(ValueError):
gc.telemetry_enabled = True

def test_setter_cannot_open_file(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/local/docker/test_container_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestContainerManager(TestCase):
Verifies functionality of ContainerManager by calling Docker APIs
"""

IMAGE = "busybox" # small sized Linux container
IMAGE = "busybox:latest" # small sized Linux container

@classmethod
def setUpClass(cls):
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/local/docker/test_lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TestLambdaContainer(TestCase):
necessary to tests them here.
"""

IMAGE_NAME = "lambci/lambda:nodejs4.3"
IMAGE_NAME = "lambci/lambda:nodejs10.x"

HELLO_WORLD_CODE = """
exports.handler = function(event, context, callback){
Expand All @@ -47,7 +47,7 @@ def setUpClass(cls):
def setUp(self):
random.seed()

self.runtime = "nodejs4.3"
self.runtime = "nodejs10.x"
self.expected_docker_image = self.IMAGE_NAME
self.handler = "index.handler"
self.layers = []
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/local/lambdafn/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

logging.basicConfig(level=logging.INFO)

RUNTIME = "nodejs4.3"
RUNTIME = "nodejs10.x"
HANDLER = "index.handler"
MEMORY = 1024

Expand Down
21 changes: 21 additions & 0 deletions tests/integration/local/invoke/test_integrations_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class TestSamPython36HelloWorldIntegration(InvokeIntegBase):
template = Path("template.yml")

@pytest.mark.flaky(reruns=3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAICE!

@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_returncode_is_zero(self):
command_list = self.get_command_list(
Expand All @@ -39,6 +40,7 @@ def test_invoke_returncode_is_zero(self):

self.assertEqual(return_code, 0)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_function_with_metadata(self):
command_list = self.get_command_list("FunctionWithMetadata", template_path=self.template_path, no_event=True)
Expand All @@ -49,6 +51,7 @@ def test_function_with_metadata(self):

self.assertEqual(process_stdout.decode("utf-8"), '"Hello World in a different dir"')

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_returns_execpted_results(self):
command_list = self.get_command_list(
Expand All @@ -60,6 +63,7 @@ def test_invoke_returns_execpted_results(self):
process_stdout = b"".join(process.stdout.readlines()).strip()
self.assertEqual(process_stdout.decode("utf-8"), '"Hello world"')

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_of_lambda_function(self):
command_list = self.get_command_list(
Expand All @@ -71,6 +75,7 @@ def test_invoke_of_lambda_function(self):
process_stdout = b"".join(process.stdout.readlines()).strip()
self.assertEqual(process_stdout.decode("utf-8"), '"Hello world"')

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
@parameterized.expand([("TimeoutFunction"), ("TimeoutFunctionWithParameter")])
def test_invoke_with_timeout_set(self, function_name):
Expand Down Expand Up @@ -98,6 +103,7 @@ def test_invoke_with_timeout_set(self, function_name):
msg="The return statement in the LambdaFunction " "should never return leading to an empty string",
)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_env_vars(self):
command_list = self.get_command_list(
Expand All @@ -112,6 +118,7 @@ def test_invoke_with_env_vars(self):
process_stdout = b"".join(process.stdout.readlines()).strip()
self.assertEqual(process_stdout.decode("utf-8"), '"MyVar"')

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_when_function_writes_stdout(self):
command_list = self.get_command_list(
Expand All @@ -127,6 +134,7 @@ def test_invoke_when_function_writes_stdout(self):
self.assertIn("Docker Lambda is writing to stdout", process_stderr.decode("utf-8"))
self.assertIn("wrote to stdout", process_stdout.decode("utf-8"))

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_when_function_writes_stderr(self):
command_list = self.get_command_list(
Expand All @@ -140,6 +148,7 @@ def test_invoke_when_function_writes_stderr(self):

self.assertIn("Docker Lambda is writing to stderr", process_stderr.decode("utf-8"))

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_returns_expected_result_when_no_event_given(self):
command_list = self.get_command_list("EchoEventFunction", template_path=self.template_path)
Expand All @@ -151,6 +160,7 @@ def test_invoke_returns_expected_result_when_no_event_given(self):
self.assertEqual(return_code, 0)
self.assertEqual("{}", process_stdout.decode("utf-8"))

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_raises_exception_with_noargs_and_event(self):
command_list = self.get_command_list(
Expand All @@ -164,6 +174,7 @@ def test_invoke_raises_exception_with_noargs_and_event(self):
error_output = process_stderr.decode("utf-8")
self.assertIn("no_event and event cannot be used together. Please provide only one.", error_output)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_env_using_parameters(self):
command_list = self.get_command_list(
Expand Down Expand Up @@ -191,6 +202,7 @@ def test_invoke_with_env_using_parameters(self):
self.assertEqual(environ["Timeout"], "100")
self.assertEqual(environ["MyRuntimeVersion"], "v0")

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_env_using_parameters_with_custom_region(self):
custom_region = "my-custom-region"
Expand All @@ -206,6 +218,7 @@ def test_invoke_with_env_using_parameters_with_custom_region(self):

self.assertEqual(environ["Region"], custom_region)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_env_with_aws_creds(self):
custom_region = "my-custom-region"
Expand Down Expand Up @@ -235,6 +248,7 @@ def test_invoke_with_env_with_aws_creds(self):
self.assertEqual(environ["AWS_SECRET_ACCESS_KEY"], secret)
self.assertEqual(environ["AWS_SESSION_TOKEN"], session)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_docker_network_of_host(self):
command_list = self.get_command_list(
Expand All @@ -249,6 +263,7 @@ def test_invoke_with_docker_network_of_host(self):

self.assertEqual(return_code, 0)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
@skipIf(IS_WINDOWS, "The test hangs on Windows due to trying to attach to a non-existing network")
def test_invoke_with_docker_network_of_host_in_env_var(self):
Expand All @@ -265,6 +280,7 @@ def test_invoke_with_docker_network_of_host_in_env_var(self):

self.assertIn('Not Found ("network non-existing-network not found")', process_stderr.decode("utf-8"))

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_sam_template_file_env_var_set(self):
command_list = self.get_command_list("HelloWorldFunctionInNonDefaultTemplate", event_path=self.event_path)
Expand All @@ -279,6 +295,7 @@ def test_sam_template_file_env_var_set(self):

self.assertEqual(process_stdout.decode("utf-8"), '"Hello world"')

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_skip_pull_image_in_env_var(self):
docker.from_env().api.pull("lambci/lambda:python3.6")
Expand All @@ -305,6 +322,7 @@ def setUp(self):
def tearDown(self):
shutil.rmtree(self.config_dir, ignore_errors=True)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_existing_env_variables_precedence_over_profiles(self):
profile = "default"
Expand Down Expand Up @@ -340,6 +358,7 @@ def test_existing_env_variables_precedence_over_profiles(self):
self.assertEqual(environ["AWS_SECRET_ACCESS_KEY"], "priority_secret_key_id")
self.assertEqual(environ["AWS_SESSION_TOKEN"], "priority_secret_token")

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_default_profile_with_custom_configs(self):
profile = "default"
Expand Down Expand Up @@ -372,6 +391,7 @@ def test_default_profile_with_custom_configs(self):
self.assertEqual(environ["AWS_SECRET_ACCESS_KEY"], "shhhhhthisisasecret")
self.assertEqual(environ["AWS_SESSION_TOKEN"], "sessiontoken")

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_custom_profile_with_custom_configs(self):
custom_config = self._create_config_file("custom")
Expand Down Expand Up @@ -403,6 +423,7 @@ def test_custom_profile_with_custom_configs(self):
self.assertEqual(environ["AWS_SECRET_ACCESS_KEY"], "shhhhhthisisasecret")
self.assertEqual(environ["AWS_SESSION_TOKEN"], "sessiontoken")

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_custom_profile_through_envrionment_variables(self):
# When using a custom profile in a custom location, you need both the config
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/local/start_lambda/test_start_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def setUp(self):
config=Config(signature_version=UNSIGNED, read_timeout=120, retries={"max_attempts": 0}),
)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_same_endpoint(self):
"""
Expand Down Expand Up @@ -64,6 +65,7 @@ def setUp(self):
config=Config(signature_version=UNSIGNED, read_timeout=120, retries={"max_attempts": 0}),
)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_non_json_data(self):
expected_error_message = (
Expand All @@ -76,6 +78,7 @@ def test_invoke_with_non_json_data(self):

self.assertEqual(str(error.exception), expected_error_message)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_log_type_not_None(self):
expected_error_message = (
Expand All @@ -88,6 +91,7 @@ def test_invoke_with_log_type_not_None(self):

self.assertEqual(str(error.exception), expected_error_message)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_invocation_type_not_RequestResponse(self):
expected_error_message = (
Expand Down Expand Up @@ -115,6 +119,7 @@ def setUp(self):
config=Config(signature_version=UNSIGNED, read_timeout=120, retries={"max_attempts": 0}),
)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_data(self):
response = self.lambda_client.invoke(FunctionName="EchoEventFunction", Payload='"This is json data"')
Expand All @@ -123,6 +128,7 @@ def test_invoke_with_data(self):
self.assertIsNone(response.get("FunctionError"))
self.assertEqual(response.get("StatusCode"), 200)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_no_data(self):
response = self.lambda_client.invoke(FunctionName="EchoEventFunction")
Expand All @@ -131,6 +137,7 @@ def test_invoke_with_no_data(self):
self.assertIsNone(response.get("FunctionError"))
self.assertEqual(response.get("StatusCode"), 200)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_log_type_None(self):
response = self.lambda_client.invoke(FunctionName="EchoEventFunction", LogType="None")
Expand All @@ -139,6 +146,7 @@ def test_invoke_with_log_type_None(self):
self.assertIsNone(response.get("FunctionError"))
self.assertEqual(response.get("StatusCode"), 200)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_invocation_type_RequestResponse(self):
response = self.lambda_client.invoke(FunctionName="EchoEventFunction", InvocationType="RequestResponse")
Expand All @@ -147,6 +155,7 @@ def test_invoke_with_invocation_type_RequestResponse(self):
self.assertIsNone(response.get("FunctionError"))
self.assertEqual(response.get("StatusCode"), 200)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_lambda_function_raised_error(self):
response = self.lambda_client.invoke(FunctionName="RaiseExceptionFunction", InvocationType="RequestResponse")
Expand All @@ -161,6 +170,7 @@ def test_lambda_function_raised_error(self):
self.assertEqual(response.get("FunctionError"), "Unhandled")
self.assertEqual(response.get("StatusCode"), 200)

@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(timeout=300, method="thread")
def test_invoke_with_function_timeout(self):
"""
Expand Down