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: Convert paths to POSIX paths before checking in esbuild handling logic #5525

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion samcli/lib/build/bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def _get_path_and_filename_from_handler(handler: str) -> Optional[str]:
:return: string path to built handler file
"""
try:
path = str(Path(handler).parent / Path(handler).stem) + ".js"
path = (Path(handler).parent / Path(handler).stem).as_posix()
path = path + ".js"
except (AttributeError, TypeError):
return None
return path
Expand Down
24 changes: 22 additions & 2 deletions tests/unit/lib/build_module/test_bundler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from pathlib import Path
from unittest import TestCase
from unittest import TestCase, skipIf
from unittest.mock import patch, Mock

from parameterized import parameterized

from samcli.lib.build.bundler import EsbuildBundlerManager
from tests.testing_utils import IS_WINDOWS
from tests.unit.commands.buildcmd.test_build_context import DummyStack


Expand Down Expand Up @@ -178,7 +179,7 @@ class PostProcessHandler(TestCase):
def test_get_path_and_filename_from_handler(self):
handler = "src/functions/FunctionName/app.Handler"
file = EsbuildBundlerManager._get_path_and_filename_from_handler(handler)
expected_path = str(Path("src") / "functions" / "FunctionName" / "app.js")
expected_path = (Path("src") / "functions" / "FunctionName" / "app.js").as_posix()
self.assertEqual(file, expected_path)

@patch("samcli.lib.build.bundler.Path.__init__")
Expand Down Expand Up @@ -240,3 +241,22 @@ def test_update_function_handler(self):
self.assertEqual(updated_handler_a, "app.handler")
self.assertEqual(updated_handler_b, "app.handler")
self.assertEqual(updated_handler_c, "functions/source/update/app.handler")

@parameterized.expand(
[("/opt/my/path/handler.handler", "/opt/my/path/handler.js"), ("handler.handler", "handler.js")]
)
def test_get_handler_path_unix(self, input_path, expected_path):
result_path = EsbuildBundlerManager(Mock())._get_path_and_filename_from_handler(input_path)

self.assertEqual(result_path, expected_path)

@parameterized.expand(
[
("\\opt\\my\\path\\handler.handler", "/opt/my/path/handler.js"),
]
)
@skipIf(not IS_WINDOWS, "Skipping POSIX converting logic since WindowsPath is not available on unix systems")
moelasmar marked this conversation as resolved.
Show resolved Hide resolved
def test_get_handler_windows_returns_posix(self, input_path, expected_path):
result_path = EsbuildBundlerManager(Mock())._get_path_and_filename_from_handler(input_path)

self.assertEqual(result_path, expected_path)