Kill the surviving mutants of the e2e command's settings, sandbox and entry point
This commit is contained in:
@@ -10,7 +10,8 @@ import unittest
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
|
||||
|
||||
from do_epic.e2e.settings import ENV_FILE, JIRA_URL, PROJECT
|
||||
from do_epic.e2e import main, sandbox, scenario
|
||||
from failure import Failure
|
||||
from do_epic.e2e import main, sandbox, scenario, settings
|
||||
|
||||
|
||||
class MainTest(unittest.TestCase):
|
||||
@@ -30,9 +31,22 @@ class MainTest(unittest.TestCase):
|
||||
code, out, err = self.run_main(["--help"])
|
||||
self.assertEqual((code, err), (0, ""))
|
||||
self.assertIn(JIRA_URL, out)
|
||||
self.assertEqual(self.run_main(["-h"])[:2], (0, out))
|
||||
code, out, err = self.run_main(["--status"])
|
||||
self.assertEqual((code, out), (1, ""))
|
||||
self.assertIn("usage: do-epic-e2e", err)
|
||||
self.assertIn(main.HELP, err)
|
||||
|
||||
|
||||
class MachineTest(unittest.TestCase):
|
||||
def test_stops_a_do_epic_that_runs_over_its_time_and_says_so(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
slow = pathlib.Path(folder) / "slow"
|
||||
slow.write_text("#!/bin/sh\nsleep 30\n", encoding="utf-8")
|
||||
slow.chmod(0o755)
|
||||
with mock.patch.object(scenario, "TIMEOUT", 1):
|
||||
done = scenario.Machine(pathlib.Path(folder), slow).do_epic("ABC-1")
|
||||
self.assertEqual(done.returncode, 124)
|
||||
self.assertIn("ran over 1 seconds", done.stderr)
|
||||
|
||||
|
||||
class ReportedTest(unittest.TestCase):
|
||||
@@ -44,18 +58,20 @@ class ReportedTest(unittest.TestCase):
|
||||
env_file.chmod(0o600)
|
||||
self.env = {JIRA_URL: "https://acme.atlassian.net", ENV_FILE: str(env_file), PROJECT: "SBX"}
|
||||
|
||||
def run_scenario(self, deleted: bool) -> tuple[int, str, str]:
|
||||
def run_scenario(self, deleted: bool, report: scenario.Report | None = None, made: str | Failure = "SBX-1") -> tuple[int, str, str]:
|
||||
@contextlib.contextmanager
|
||||
def epic_made(*args: object) -> typing.Iterator[str]:
|
||||
yield "SBX-1"
|
||||
def epic_made(*args: object) -> typing.Iterator[str | Failure]:
|
||||
self.made_with = args
|
||||
yield made
|
||||
if not deleted:
|
||||
raise sandbox.Leftover("SBX-1 is still there")
|
||||
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
report = scenario.Report(["a check held"], ["a check broke"])
|
||||
with mock.patch.object(sandbox, "epic_made", epic_made), mock.patch.object(scenario, "run", return_value=report):
|
||||
report = report or scenario.Report(["a check held"], ["a check broke"])
|
||||
with mock.patch.object(sandbox, "epic_made", epic_made), mock.patch.object(scenario, "run", return_value=report) as ran:
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
code = main.main([], self.env, pathlib.Path("do-epic"))
|
||||
self.ran_with = ran.call_args.args if ran.called else None
|
||||
return code, out.getvalue(), err.getvalue()
|
||||
|
||||
def test_prints_each_check_and_fails_where_one_broke(self) -> None:
|
||||
@@ -69,14 +85,18 @@ class ReportedTest(unittest.TestCase):
|
||||
self.assertIn("ok a check held", out)
|
||||
self.assertIn("SBX-1 is still there", err)
|
||||
|
||||
def test_makes_the_epic_in_the_sandbox_and_runs_the_scenario_on_it(self) -> None:
|
||||
code, out, err = self.run_scenario(True, scenario.Report(["a check held"]))
|
||||
sandbox_set = settings.read(self.env)
|
||||
self.assertEqual((code, err), (0, ""))
|
||||
self.assertEqual(self.made_with, (sandbox_set, "do-epic e2e sandbox epic"))
|
||||
self.assertEqual(self.ran_with, (sandbox_set, "SBX-1", pathlib.Path("do-epic")))
|
||||
self.assertEqual(out, "Sandbox epic SBX-1 in https://acme.atlassian.net\nok a check held\n1 held, 0 broke\n")
|
||||
|
||||
class MachineTest(unittest.TestCase):
|
||||
def test_stops_a_do_epic_that_runs_over_its_time_and_says_so(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
slow = pathlib.Path(folder) / "slow"
|
||||
slow.write_text("#!/bin/sh\nsleep 30\n", encoding="utf-8")
|
||||
slow.chmod(0o755)
|
||||
with mock.patch.object(scenario, "TIMEOUT", 1):
|
||||
done = scenario.Machine(pathlib.Path(folder), slow).do_epic("ABC-1")
|
||||
self.assertEqual(done.returncode, 124)
|
||||
self.assertIn("ran over 1 seconds", done.stderr)
|
||||
def test_fails_without_a_scenario_where_the_epic_cannot_be_made(self) -> None:
|
||||
code, out, err = self.run_scenario(True, made=Failure("Jira said no"))
|
||||
self.assertEqual((code, out, self.ran_with), (1, "", None))
|
||||
self.assertEqual(err, "do-epic-e2e: Jira said no\n")
|
||||
|
||||
def test_fails_where_every_check_held_but_the_epic_stays(self) -> None:
|
||||
self.assertEqual(self.run_scenario(False, scenario.Report(["a check held"]))[0], 1)
|
||||
|
||||
Reference in New Issue
Block a user