forked from aws/aws-sam-cli
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_lambda_debug_settings.py
More file actions
83 lines (73 loc) · 3.33 KB
/
Copy pathtest_lambda_debug_settings.py
File metadata and controls
83 lines (73 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from unittest import TestCase
from unittest.mock import patch, Mock
from parameterized import parameterized
from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported, LambdaDebugSettings, Runtime
_DEBUG_RUNTIMES = [
Runtime.java8al2,
Runtime.java11,
Runtime.java17,
Runtime.java21,
Runtime.java25,
Runtime.dotnet6,
Runtime.dotnet8,
Runtime.dotnet10,
Runtime.go1x,
Runtime.nodejs16x,
Runtime.nodejs18x,
Runtime.nodejs20x,
Runtime.nodejs22x,
Runtime.nodejs24x,
Runtime.python38,
Runtime.python39,
Runtime.python310,
Runtime.python311,
Runtime.python312,
Runtime.python313,
Runtime.python314,
]
class TestLambdaDebugSettings(TestCase):
@parameterized.expand(
[
(["-delveAPI=2"], 2),
(["-delveAPI=1"], 1),
(["-delveAPI", "2"], 2),
(["-delveAPI", "1"], 1),
# default should be 1
([], 1),
]
)
def test_delve_api_version_parsing(self, debug_arg_list, expected_api_version):
self.assertEqual(LambdaDebugSettings.parse_go_delve_api_version(debug_arg_list), expected_api_version)
@parameterized.expand(
[
(["-delveApi=2"],),
(["-delveApi", "2"],),
]
)
def test_unrecognized_delve_api_version_parsing(self, debug_arg_list):
with patch("samcli.local.docker.lambda_debug_settings.LOG.warning") as warning_mock:
self.assertEqual(LambdaDebugSettings.parse_go_delve_api_version(debug_arg_list), 1)
warning_mock.assert_called_once_with(
'Ignoring unrecognized arguments: %s. Only "-delveAPI" is supported.', debug_arg_list
)
@parameterized.expand([(runtime,) for runtime in _DEBUG_RUNTIMES])
@patch("samcli.local.docker.lambda_debug_settings.DebugSettings")
def test_only_one_debug_setting_is_created(self, runtime, debug_settings_mock):
LambdaDebugSettings.get_debug_settings(1234, [], {}, runtime.value, {})
debug_settings_mock.assert_called_once()
@parameterized.expand([(runtime,) for runtime in Runtime if runtime not in _DEBUG_RUNTIMES])
@patch("samcli.local.docker.lambda_debug_settings.DebugSettings")
def test_debugging_not_supported_raised(self, runtime, debug_settings_mock):
with self.assertRaises(DebuggingNotSupported):
LambdaDebugSettings.get_debug_settings(1234, [], {}, runtime.value, {})
debug_settings_mock.assert_not_called()
@patch("samcli.local.docker.lambda_debug_settings.LambdaDebugSettings.parse_go_delve_api_version")
def test_parse_go_delve_api_version_called_for_go_runtimes(self, parse_go_delve_api_version_mock):
debug_args_list = Mock()
LambdaDebugSettings.get_debug_settings(1234, debug_args_list, {}, Runtime.go1x.value, {})
parse_go_delve_api_version_mock.assert_called_once_with(debug_args_list)
@parameterized.expand([(runtime,) for runtime in _DEBUG_RUNTIMES if runtime != Runtime.go1x])
@patch("samcli.local.docker.lambda_debug_settings.LambdaDebugSettings.parse_go_delve_api_version")
def test_parse_go_delve_api_version_not_called_for_other_runtimes(self, runtime, parse_go_delve_api_version_mock):
LambdaDebugSettings.get_debug_settings(1234, [], {}, runtime.value, {})
parse_go_delve_api_version_mock.assert_not_called()