Skip to content

Commit

Permalink
fix: pass unpatched runtime to lambda builder (#6988)
Browse files Browse the repository at this point in the history
* fix: pass unpatched runtime to lambda builder

* add unit test
  • Loading branch information
sidhujus authored Apr 29, 2024
1 parent 278e464 commit 445005c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
5 changes: 3 additions & 2 deletions samcli/lib/build/app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,16 @@ def _build_function_in_process(
application_framework=config.application_framework,
)

runtime = patch_runtime(runtime)
runtime_patched = patch_runtime(runtime)

try:
builder.build(
source_dir,
artifacts_dir,
scratch_dir,
manifest_path,
runtime=runtime,
runtime=runtime_patched,
unpatched_runtime=runtime,
executable_search_paths=config.executable_search_paths,
mode=self._mode,
options=options,
Expand Down
59 changes: 59 additions & 0 deletions tests/unit/lib/build_module/test_app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,7 @@ def test_must_use_lambda_builder(
"scratch_dir",
"manifest_path",
runtime="runtime",
unpatched_runtime="runtime",
executable_search_paths=config_mock.executable_search_paths,
mode="mode",
options=None,
Expand All @@ -2573,6 +2574,63 @@ def test_must_use_lambda_builder(

patch_runtime_mock.assert_called_with("runtime")

@parameterized.expand([("provided.al2",), ("provided.al2023",)])
@patch("samcli.lib.telemetry.event.EventType.get_accepted_values")
@patch("samcli.lib.build.app_builder.LambdaBuilder")
@patch("samcli.lib.build.app_builder.get_enabled_experimental_flags")
def test_pass_unpatched_runtime_to_lambda_builder(
self,
runtime,
experimental_flags_mock,
lambda_builder_mock,
event_mock,
):
experimental_flags_mock.return_value = ["experimental_flags"]
config_mock = Mock()
builder_instance_mock = lambda_builder_mock.return_value = Mock()
event_mock.return_value = [runtime]

result = self.builder._build_function_in_process(
config_mock,
"source_dir",
"artifacts_dir",
"scratch_dir",
"manifest_path",
runtime,
X86_64,
None,
None,
True,
True,
is_building_layer=False,
)
self.assertEqual(result, "artifacts_dir")

lambda_builder_mock.assert_called_with(
language=config_mock.language,
dependency_manager=config_mock.dependency_manager,
application_framework=config_mock.application_framework,
)

builder_instance_mock.build.assert_called_with(
"source_dir",
"artifacts_dir",
"scratch_dir",
"manifest_path",
runtime="provided",
unpatched_runtime=runtime,
executable_search_paths=config_mock.executable_search_paths,
mode="mode",
options=None,
architecture=X86_64,
dependencies_dir=None,
download_dependencies=True,
combine_dependencies=True,
is_building_layer=False,
experimental_flags=["experimental_flags"],
build_in_source=False,
)

@patch("samcli.lib.build.app_builder.LambdaBuilder")
def test_must_raise_on_error(self, lambda_builder_mock):
config_mock = Mock()
Expand Down Expand Up @@ -2626,6 +2684,7 @@ def test_building_with_experimental_flags(
"scratch_dir",
"manifest_path",
runtime="runtime",
unpatched_runtime="runtime",
executable_search_paths=ANY,
mode="mode",
options=None,
Expand Down

0 comments on commit 445005c

Please sign in to comment.