Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: --base-dir is disregarded in sam build #2718

Merged
merged 6 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix unit tests
  • Loading branch information
aahung committed Mar 16, 2021
commit a32bda3ccf9f22a4e8d0e340ca0bd75d3673d820
10 changes: 5 additions & 5 deletions samcli/lib/providers/sam_function_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_all(self) -> Iterator[Function]:

@staticmethod
def _extract_functions(
stacks: List[Stack], use_raw_codeuri: bool, ignore_code_extraction_warnings: bool
stacks: List[Stack], use_raw_codeuri: bool = False, ignore_code_extraction_warnings: bool = False
) -> Dict[str, Function]:
"""
Extracts and returns function information from the given dictionary of SAM/CloudFormation resources. This
Expand Down Expand Up @@ -168,7 +168,7 @@ def _convert_sam_function_resource(
name: str,
resource_properties: Dict,
layers: List[LayerVersion],
use_raw_codeuri: bool,
use_raw_codeuri: bool = False,
ignore_code_extraction_warnings: bool = False,
) -> Function:
"""
Expand Down Expand Up @@ -214,7 +214,7 @@ def _convert_sam_function_resource(

@staticmethod
def _convert_lambda_function_resource(
stack: Stack, name: str, resource_properties: Dict, layers: List[LayerVersion], use_raw_codeuri: bool
stack: Stack, name: str, resource_properties: Dict, layers: List[LayerVersion], use_raw_codeuri: bool = False
) -> Function:
"""
Converts a AWS::Lambda::Function resource to a Function configuration usable by the provider.
Expand Down Expand Up @@ -271,7 +271,7 @@ def _build_function_configuration(
layers: List,
inlinecode: Optional[str],
imageuri: Optional[str],
use_raw_codeuri: bool,
use_raw_codeuri: bool = False,
) -> Function:
"""
Builds a Function configuration usable by the provider.
Expand Down Expand Up @@ -328,7 +328,7 @@ def _build_function_configuration(
def _parse_layer_info(
stack: Stack,
list_of_layers: List[Any],
use_raw_codeuri: bool,
use_raw_codeuri: bool = False,
ignore_code_extraction_warnings: bool = False,
) -> List[LayerVersion]:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/commands/buildcmd/test_build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_must_setup_context(
self.assertTrue(layer1 in resources_to_build.layers)

get_buildable_stacks_mock.assert_called_once_with("template_file", parameter_overrides={"overrides": "value"})
SamFunctionProviderMock.assert_called_once_with([stack])
SamFunctionProviderMock.assert_called_once_with([stack], False)
pathlib_mock.Path.assert_called_once_with("template_file")
setup_build_dir_mock.assert_called_with("build_dir", True)
ContainerManagerMock.assert_called_once_with(docker_network_id="network", skip_pull_image=True)
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_must_return_many_functions_to_build(
self.assertEqual(resources_to_build.functions, [func1, func2])
self.assertEqual(resources_to_build.layers, [layer1])
get_buildable_stacks_mock.assert_called_once_with("template_file", parameter_overrides={"overrides": "value"})
SamFunctionProviderMock.assert_called_once_with([stack])
SamFunctionProviderMock.assert_called_once_with([stack], False)
pathlib_mock.Path.assert_called_once_with("template_file")
setup_build_dir_mock.assert_called_with("build_dir", True)
ContainerManagerMock.assert_called_once_with(docker_network_id="network", skip_pull_image=True)
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/commands/local/lib/test_sam_function_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def test_must_extract_functions(self, get_template_mock, extract_mock):
stack = make_root_stack(template, self.parameter_overrides)
provider = SamFunctionProvider([stack])

extract_mock.assert_called_with([stack], False)
extract_mock.assert_called_with([stack], False, False)
get_template_mock.assert_called_with(template, self.parameter_overrides)
self.assertEqual(provider.functions, extract_result)

Expand All @@ -609,7 +609,7 @@ def test_must_default_to_empty_resources(self, get_template_mock, extract_mock):
stack = make_root_stack(template, self.parameter_overrides)
provider = SamFunctionProvider([stack])

extract_mock.assert_called_with([stack], False) # Empty Resources value must be passed
extract_mock.assert_called_with([stack], False, False) # Empty Resources value must be passed
self.assertEqual(provider.functions, extract_result)


Expand All @@ -627,7 +627,7 @@ def test_must_work_for_sam_function(self, convert_mock, resources_mock):
stack = make_root_stack(None)
result = SamFunctionProvider._extract_functions([stack])
self.assertEqual(expected, result)
convert_mock.assert_called_with(stack, "Func1", {"a": "b"}, [], ignore_code_extraction_warnings=False)
convert_mock.assert_called_with(stack, "Func1", {"a": "b"}, [], False, ignore_code_extraction_warnings=False)

@patch("samcli.lib.providers.sam_function_provider.Stack.resources", new_callable=PropertyMock)
@patch.object(SamFunctionProvider, "_convert_sam_function_resource")
Expand All @@ -648,7 +648,7 @@ def test_must_work_with_no_properties(self, convert_mock, resources_mock):
stack = make_root_stack(None)
result = SamFunctionProvider._extract_functions([stack])
self.assertEqual(expected, result)
convert_mock.assert_called_with(stack, "Func1", {}, [], ignore_code_extraction_warnings=False)
convert_mock.assert_called_with(stack, "Func1", {}, [], False, ignore_code_extraction_warnings=False)

@patch("samcli.lib.providers.sam_function_provider.Stack.resources", new_callable=PropertyMock)
@patch.object(SamFunctionProvider, "_convert_lambda_function_resource")
Expand All @@ -664,7 +664,7 @@ def test_must_work_for_lambda_function(self, convert_mock, resources_mock):
stack = make_root_stack(None)
result = SamFunctionProvider._extract_functions([stack])
self.assertEqual(expected, result)
convert_mock.assert_called_with(stack, "Func1", {"a": "b"}, [])
convert_mock.assert_called_with(stack, "Func1", {"a": "b"}, [], False)

@patch("samcli.lib.providers.sam_function_provider.Stack.resources", new_callable=PropertyMock)
def test_must_skip_unknown_resource(self, resources_mock):
Expand Down Expand Up @@ -705,8 +705,8 @@ def test_must_work_for_multiple_functions_with_name_but_in_different_stacks(
self.assertEqual(expected, result)
convert_mock.assert_has_calls(
[
call(stack_root, "Func1", {"a": "b"}, []),
call(stack_child, "Func1", {"a": "b"}, []),
call(stack_root, "Func1", {"a": "b"}, [], False),
call(stack_child, "Func1", {"a": "b"}, [], False),
]
)

Expand Down