diff --git a/samcli/local/docker/container.py b/samcli/local/docker/container.py index 09fadcd5d6..8170f88366 100644 --- a/samcli/local/docker/container.py +++ b/samcli/local/docker/container.py @@ -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 = { @@ -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 diff --git a/samcli/local/docker/lambda_container.py b/samcli/local/docker/lambda_container.py index d42f7b37c7..cf4b9c5154 100644 --- a/samcli/local/docker/lambda_container.py +++ b/samcli/local/docker/lambda_container.py @@ -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) diff --git a/tests/integration/local/invoke/invoke_integ_base.py b/tests/integration/local/invoke/invoke_integ_base.py index c95fc7be9a..f30cc8db96 100644 --- a/tests/integration/local/invoke/invoke_integ_base.py +++ b/tests/integration/local/invoke/invoke_integ_base.py @@ -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"] diff --git a/tests/integration/local/invoke/test_invoke_build_in_source.py b/tests/integration/local/invoke/test_invoke_build_in_source.py index 7c7afaeb42..ee900c1784 100644 --- a/tests/integration/local/invoke/test_invoke_build_in_source.py +++ b/tests/integration/local/invoke/test_invoke_build_in_source.py @@ -26,6 +26,7 @@ def tearDown(self): except: pass + class TestInvokeBuildInSourceSymlinkedModules(BuildInSourceInvokeBase): project_test_folder = "build-in-source" @@ -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) @@ -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) diff --git a/tests/unit/local/docker/test_container.py b/tests/unit/local/docker/test_container.py index b965dc05f0..0ac4e9c8fa 100644 --- a/tests/unit/local/docker/test_container.py +++ b/tests/unit/local/docker/test_container.py @@ -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 @@ -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. @@ -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. @@ -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 @@ -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 @@ -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()) @@ -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, {}) @@ -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}}) diff --git a/tests/unit/local/docker/test_lambda_container.py b/tests/unit/local/docker/test_lambda_container.py index 3834d98def..f7bc1e54a2 100644 --- a/tests/unit/local/docker/test_lambda_container.py +++ b/tests/unit/local/docker/test_lambda_container.py @@ -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 = {} @@ -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"