Skip to content

Commit

Permalink
Unprivate static method and make format
Browse files Browse the repository at this point in the history
  • Loading branch information
lucashuy committed Nov 9, 2023
1 parent 7dfcffe commit dc59721
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions samcli/local/docker/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def create(self):
"bind": self._working_dir,
"mode": mount_mode,
},
**Container._create_mapped_symlink_files(self._host_dir, self._working_dir),
**Container.create_mapped_symlink_files(self._host_dir, self._working_dir),
}

kwargs = {
Expand Down Expand Up @@ -227,7 +227,7 @@ def create(self):
return self.id

@staticmethod
def _create_mapped_symlink_files(search_directory: str, bind_directory: str) -> Dict[str, Dict[str, str]]:
def create_mapped_symlink_files(search_directory: str, bind_directory: str) -> Dict[str, Dict[str, str]]:
"""
Resolves any top level symlinked files and folders that are found on the
host directory and creates additional bind mounts to correctly map them
Expand Down
2 changes: 1 addition & 1 deletion samcli/local/docker/lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _get_layer_folder_mounts(layers: List[LayerVersion]) -> Dict[str, Dict[str,
# eg. `/opt` + `nodejs`
container_bind_path = Path(LambdaImage._LAYERS_DIR, layer_folder)

mappings = LambdaContainer._create_mapped_symlink_files(
mappings = LambdaContainer.create_mapped_symlink_files(
str(artifact_layer_path), str(container_bind_path)
)
layer_mappings.update(mappings)
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/local/invoke/invoke_integ_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ def get_command_list(
return command_list

def get_build_command_list(
self, template_path=None, cached=None, parallel=None, use_container=None, build_dir=None, build_in_source=None,
self,
template_path=None,
cached=None,
parallel=None,
use_container=None,
build_dir=None,
build_in_source=None,
):
command_list = [self.cmd, "build"]

Expand Down
9 changes: 7 additions & 2 deletions tests/integration/local/invoke/test_invoke_build_in_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def tearDown(self):
except:
pass


class TestInvokeBuildInSourceSymlinkedModules(BuildInSourceInvokeBase):
project_test_folder = "build-in-source"

Expand All @@ -40,7 +41,9 @@ def _validate_modules_linked(self):
self.assertEqual(os.path.islink(local_dep), False)

def test_successful_invoke(self):
build_command = self.get_build_command_list(template_path=self.template_path, build_dir=self.build_dir, build_in_source=True)
build_command = self.get_build_command_list(
template_path=self.template_path, build_dir=self.build_dir, build_in_source=True
)
_, _, exit_code = self.run_command(build_command)

self.assertEqual(exit_code, 0)
Expand All @@ -59,7 +62,9 @@ class TestInvokeBuildInSourceSymlinkedLayers(BuildInSourceInvokeBase):
project_test_folder = str(Path("build-in-source", "layer_symlink"))

def test_successful_invoke(self):
build_command = self.get_build_command_list(template_path=self.template_path, build_dir=self.build_dir, build_in_source=True)
build_command = self.get_build_command_list(
template_path=self.template_path, build_dir=self.build_dir, build_in_source=True
)

_, _, exit_code = self.run_command(build_command, cwd=self.test_project_folder)

Expand Down
16 changes: 8 additions & 8 deletions tests/unit/local/docker/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def setUp(self):
self.mock_docker_client.networks = Mock()
self.mock_docker_client.networks.get = Mock()

@patch("samcli.local.docker.container.Container._create_mapped_symlink_files")
@patch("samcli.local.docker.container.Container.create_mapped_symlink_files")
def test_must_create_container_with_required_values(self, mock_resolve_symlinks):
"""
Create a container with only required values. Optional values are not provided
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_must_create_container_with_required_values(self, mock_resolve_symlinks)
)
self.mock_docker_client.networks.get.assert_not_called()

@patch("samcli.local.docker.container.Container._create_mapped_symlink_files")
@patch("samcli.local.docker.container.Container.create_mapped_symlink_files")
def test_must_create_container_including_all_optional_values(self, mock_resolve_symlinks):
"""
Create a container with required and optional values.
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_must_create_container_including_all_optional_values(self, mock_resolve_
self.mock_docker_client.networks.get.assert_not_called()

@patch("samcli.local.docker.utils.os")
@patch("samcli.local.docker.container.Container._create_mapped_symlink_files")
@patch("samcli.local.docker.container.Container.create_mapped_symlink_files")
def test_must_create_container_translate_volume_path(self, mock_resolve_symlinks, os_mock):
"""
Create a container with required and optional values, with windows style volume mount.
Expand Down Expand Up @@ -236,7 +236,7 @@ def test_must_create_container_translate_volume_path(self, mock_resolve_symlinks
)
self.mock_docker_client.networks.get.assert_not_called()

@patch("samcli.local.docker.container.Container._create_mapped_symlink_files")
@patch("samcli.local.docker.container.Container.create_mapped_symlink_files")
def test_must_connect_to_network_on_create(self, mock_resolve_symlinks):
"""
Create a container with only required values. Optional values are not provided
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_must_connect_to_network_on_create(self, mock_resolve_symlinks):
self.mock_docker_client.networks.get.assert_called_with(network_id)
network_mock.connect.assert_called_with(container_id)

@patch("samcli.local.docker.container.Container._create_mapped_symlink_files")
@patch("samcli.local.docker.container.Container.create_mapped_symlink_files")
def test_must_connect_to_host_network_on_create(self, mock_resolve_symlinks):
"""
Create a container with only required values. Optional values are not provided
Expand Down Expand Up @@ -981,7 +981,7 @@ def test_real_container_is_running_return_true(self):
self.assertTrue(self.container.is_created())


class TestContainer_create_mapped_symlink_files(TestCase):
class TestContainercreate_mapped_symlink_files(TestCase):
def setUp(self):
self.container = Container(Mock(), Mock(), Mock(), Mock(), docker_client=Mock())

Expand All @@ -997,7 +997,7 @@ def test_no_symlinks_returns_empty(self, mock_scandir):
mock_context.__enter__ = Mock(return_value=[self.mock_regular_file])
mock_scandir.return_value = mock_context

volumes = Container._create_mapped_symlink_files("mock_host_dir", "mock_container_dir")
volumes = Container.create_mapped_symlink_files("mock_host_dir", "mock_container_dir")

self.assertEqual(volumes, {})

Expand All @@ -1017,6 +1017,6 @@ def test_resolves_symlink(self, mock_path, mock_realpath, mock_scandir):
mock_context.__enter__ = Mock(return_value=[self.mock_symlinked_file])
mock_scandir.return_value = mock_context

volumes = Container._create_mapped_symlink_files("mock_host_dir", "mock_container_dir")
volumes = Container.create_mapped_symlink_files("mock_host_dir", "mock_container_dir")

self.assertEqual(volumes, {host_path: {"bind": container_path, "mode": ANY}})
4 changes: 2 additions & 2 deletions tests/unit/local/docker/test_lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def test_returns_no_mounts_invalid_layer(self, layer):

self.assertEqual(result, {})

@patch.object(LambdaContainer, "_create_mapped_symlink_files")
@patch.object(LambdaContainer, "create_mapped_symlink_files")
def test_returns_no_mounts_no_links(self, create_map_mock):
create_map_mock.return_value = {}

Expand All @@ -644,7 +644,7 @@ def test_returns_no_mounts_no_links(self, create_map_mock):
create_map_mock.assert_called_once()
self.assertEqual(result, {})

@patch.object(LambdaContainer, "_create_mapped_symlink_files")
@patch.object(LambdaContainer, "create_mapped_symlink_files")
def test_returns_mounts(self, create_map_mock):
code_uri = "some/path"
runtime = "nodejs18.x"
Expand Down

0 comments on commit dc59721

Please sign in to comment.