Skip to content
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
12 changes: 7 additions & 5 deletions aws_lambda_builders/workflows/ruby_bundler/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def __init__(self, source_dir, subprocess_bundler):
def execute(self):
try:
LOG.debug("Running bundle install in %s", self.source_dir)
self.subprocess_bundler.run(["install", "--without", "development", "test"], cwd=self.source_dir)
self.subprocess_bundler.run(
["config", "set", "--local", "without", "development:test"], cwd=self.source_dir
)
self.subprocess_bundler.run(["install"], cwd=self.source_dir)
except BundlerExecutionError as ex:
raise ActionFailedError(str(ex))

Expand All @@ -49,9 +52,8 @@ def __init__(self, source_dir, subprocess_bundler):

def execute(self):
try:
LOG.debug("Running bundle install --deployment in %s", self.source_dir)
self.subprocess_bundler.run(
["install", "--deployment", "--without", "development", "test"], cwd=self.source_dir
)
LOG.debug("Running bundle install with deployment enabled in %s", self.source_dir)
self.subprocess_bundler.run(["config", "set", "--local", "deployment", "true"], cwd=self.source_dir)
self.subprocess_bundler.run(["install"], cwd=self.source_dir)
except BundlerExecutionError as ex:
raise ActionFailedError(str(ex))
16 changes: 12 additions & 4 deletions tests/unit/workflows/ruby_bundler/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unittest import TestCase
from unittest.mock import patch
from unittest.mock import patch, call

from aws_lambda_builders.actions import ActionFailedError
from aws_lambda_builders.workflows.ruby_bundler.actions import RubyBundlerInstallAction, RubyBundlerVendorAction
Expand All @@ -12,7 +12,12 @@ def test_runs_bundle_install(self, SubprocessBundlerMock):
subprocess_bundler = SubprocessBundlerMock.return_value
action = RubyBundlerInstallAction("source_dir", subprocess_bundler=subprocess_bundler)
action.execute()
subprocess_bundler.run.assert_called_with(["install", "--without", "development", "test"], cwd="source_dir")
subprocess_bundler.run.assert_has_calls(
[
call(["config", "set", "--local", "without", "development:test"], cwd="source_dir"),
call(["install"], cwd="source_dir"),
]
)

@patch("aws_lambda_builders.workflows.ruby_bundler.bundler.SubprocessBundler")
def test_raises_action_failed_on_failure(self, SubprocessBundlerMock):
Expand All @@ -31,8 +36,11 @@ def test_runs_bundle_install_deployment(self, SubprocessBundlerMock):
subprocess_bundler = SubprocessBundlerMock.return_value
action = RubyBundlerVendorAction("source_dir", subprocess_bundler=subprocess_bundler)
action.execute()
subprocess_bundler.run.assert_called_with(
["install", "--deployment", "--without", "development", "test"], cwd="source_dir"
subprocess_bundler.run.assert_has_calls(
[
call(["config", "set", "--local", "deployment", "true"], cwd="source_dir"),
call(["install"], cwd="source_dir"),
]
)

@patch("aws_lambda_builders.workflows.ruby_bundler.bundler.SubprocessBundler")
Expand Down
38 changes: 15 additions & 23 deletions tests/unit/workflows/ruby_bundler/test_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,38 @@ def setUp(self, OSUtilMock):
def test_run_executes_bundler_on_nixes(self):
self.osutils.is_windows.side_effect = [False]
self.under_test = SubprocessBundler(self.osutils)
self.under_test.run(["install", "--without", "development", "test"])
self.osutils.popen.assert_called_with(
["bundle", "install", "--without", "development", "test"], cwd=None, stderr="PIPE", stdout="PIPE"
)
self.under_test.run(["install"])
self.osutils.popen.assert_called_with(["bundle", "install"], cwd=None, stderr="PIPE", stdout="PIPE")

def test_run_executes_bundler_on_windows(self):
self.osutils.is_windows.side_effect = [True]
self.under_test = SubprocessBundler(self.osutils)
self.under_test.run(["install", "--without", "development", "test"])
self.osutils.popen.assert_called_with(
["bundler.bat", "install", "--without", "development", "test"], cwd=None, stderr="PIPE", stdout="PIPE"
)
self.under_test.run(["install"])
self.osutils.popen.assert_called_with(["bundler.bat", "install"], cwd=None, stderr="PIPE", stdout="PIPE")

def test_uses_custom_bundler_path_if_supplied(self):
self.under_test.run(["install", "--without", "development", "test"])
self.osutils.popen.assert_called_with(
["/a/b/c/bundle", "install", "--without", "development", "test"], cwd=None, stderr="PIPE", stdout="PIPE"
)
self.under_test.run(["install"])
self.osutils.popen.assert_called_with(["/a/b/c/bundle", "install"], cwd=None, stderr="PIPE", stdout="PIPE")

def test_uses_cwd_if_supplied(self):
self.under_test.run(["install", "--without", "development", "test"], cwd="/a/cwd")
self.osutils.popen.assert_called_with(
["/a/b/c/bundle", "install", "--without", "development", "test"], cwd="/a/cwd", stderr="PIPE", stdout="PIPE"
)
self.under_test.run(["install"], cwd="/a/cwd")
self.osutils.popen.assert_called_with(["/a/b/c/bundle", "install"], cwd="/a/cwd", stderr="PIPE", stdout="PIPE")

def test_returns_popen_out_decoded_if_retcode_is_0(self):
self.popen.out = b"some encoded text\n\n"
result = self.under_test.run(["install", "--without", "development", "test"])
result = self.under_test.run(["install"])
self.assertEqual(result, "some encoded text")

def test_logs_warning_when_gemfile_missing(self):
self.popen.returncode = 10
with patch.object(logger, "warning") as mock_warning:
self.under_test.run(["install", "--without", "development", "test"])
self.under_test.run(["install"])
mock_warning.assert_called_once_with("Gemfile not found. Continuing the build without dependencies.")

def test_bundle_file_removed_if_generated(self):
self.popen.returncode = 10
self.osutils.directory_exists.return_value = True
self.under_test.run(["install", "--without", "development", "test"])
self.under_test.run(["install"])
self.osutils.get_bundle_dir.assert_called_once()
self.osutils.remove_directory.assert_called_once()

Expand All @@ -79,30 +71,30 @@ def test_raises_BundlerExecutionError_with_stdout_text_if_retcode_is_not_0(self)
self.popen.out = b"some error text\n\n"
self.popen.err = b""
with self.assertRaises(BundlerExecutionError) as raised:
self.under_test.run(["install", "--without", "development", "test"])
self.under_test.run(["install"])
self.assertEqual(raised.exception.args[0], "Bundler Failed: some error text")

def test_raises_BundlerExecutionError_with_stderr_text_if_retcode_is_not_0(self):
self.popen.returncode = 1
self.popen.err = b"some error text\n\n"
self.popen.out = b""
with self.assertRaises(BundlerExecutionError) as raised:
self.under_test.run(["install", "--without", "development", "test"])
self.under_test.run(["install"])
self.assertEqual(raised.exception.args[0], "Bundler Failed: some error text")

def test_raises_BundlerExecutionError_with_both_stderr_and_stdout_text_if_retcode_is_not_0(self):
self.popen.returncode = 1
self.popen.err = b"some error text from stderr\n\n"
self.popen.out = b"some error text from stdout\n\n"
with self.assertRaises(BundlerExecutionError) as raised:
self.under_test.run(["install", "--without", "development", "test"])
self.under_test.run(["install"])
self.assertEqual(
raised.exception.args[0], f"Bundler Failed: some error text from stdout{linesep}some error text from stderr"
)

def test_raises_ValueError_if_args_not_a_list(self):
with self.assertRaises(ValueError) as raised:
self.under_test.run(("install", "--without", "development", "test"))
self.under_test.run("install")
self.assertEqual(raised.exception.args[0], "args must be a list")

def test_raises_ValueError_if_args_empty(self):
Expand Down
Loading