Skip to content

Commit 47b65ec

Browse files
committed
Simplify current-lab up branch logic and add no-start regression test.
Replace the unreachable conditional with the equivalent branch and verify up --no-start preserves the current-lab path without starting it.
1 parent b936f6b commit 47b65ec

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

tests/v2/up.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from .mocks.github import MockGitHub # noqa
77

88
try:
9-
from unittest.mock import patch
9+
from unittest.mock import Mock, patch
1010
except ImportError:
11-
from mock import patch # noqa
11+
from mock import Mock, patch # noqa
1212

1313

1414
class TestCMLUp(BaseCMLTest):
@@ -189,6 +189,49 @@ def test_cml_up_after_use(self):
189189
"Lab {} (ID: {}) is already set as the current lab".format(self.get_test_title(), self.get_test_id()), result.output
190190
)
191191

192+
def test_cml_up_after_use_no_start(self):
193+
super().setUp()
194+
with self.get_context() as m:
195+
# Mock the request to return what we expect from the API.
196+
self.setup_mocks(m)
197+
virl = self.get_virl()
198+
runner = CliRunner()
199+
result = runner.invoke(virl, ["up", "--no-start"])
200+
self.assertEqual(0, result.exit_code)
201+
self.assertIn(
202+
"Lab {} (ID: {}) is already set as the current lab".format(self.get_test_title(), self.get_test_id()), result.output
203+
)
204+
self.assertNotIn("Starting lab", result.output)
205+
206+
@patch("virl.cli.up.commands.start_lab", autospec=False)
207+
@patch("virl.cli.up.commands.safe_join_existing_lab", autospec=False)
208+
@patch("virl.cli.up.commands.get_current_lab", autospec=False)
209+
@patch("virl.cli.up.commands.get_cml_client", autospec=False)
210+
@patch("virl.cli.up.commands.VIRLServer", autospec=False)
211+
def test_cml_up_after_use_starts_inactive_current_lab(
212+
self,
213+
_server_mock,
214+
get_cml_client_mock,
215+
get_current_lab_mock,
216+
safe_join_existing_lab_mock,
217+
start_lab_mock,
218+
):
219+
get_cml_client_mock.return_value = object()
220+
get_current_lab_mock.return_value = "current-lab-id"
221+
inactive_lab = Mock()
222+
inactive_lab.id = "current-lab-id"
223+
inactive_lab.title = "Current Lab"
224+
inactive_lab.is_active.return_value = False
225+
safe_join_existing_lab_mock.return_value = inactive_lab
226+
227+
virl = self.get_virl()
228+
runner = CliRunner()
229+
result = runner.invoke(virl, ["up"])
230+
231+
self.assertEqual(0, result.exit_code)
232+
self.assertIn("Lab Current Lab (ID: current-lab-id) is already set as the current lab", result.output)
233+
start_lab_mock.assert_called_once_with(inactive_lab, False)
234+
192235
def test_cml_up_running_lab(self):
193236
with self.get_context() as m:
194237
# Mock the request to return what we expect from the API.

virl/cli/up/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def up(repo=None, provision=False, start=True, **kwargs):
199199
else:
200200
click.secho("Could not find a lab to start. Maybe try -f", fg="red")
201201
exit(1)
202-
elif clab:
202+
else:
203203
click.secho("Lab {} (ID: {}) is already set as the current lab".format(clab.title, current_lab))
204204
if not clab.is_active() and start:
205205
start_lab(clab, provision)

0 commit comments

Comments
 (0)