47 lines
2.0 KiB
Python
47 lines
2.0 KiB
Python
import pathlib
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
|
|
|
|
from do_epic.config import load
|
|
from do_epic.e2e import scenario
|
|
from do_epic.e2e.settings import Sandbox
|
|
from failure import Failure
|
|
|
|
|
|
class ReportTest(unittest.TestCase):
|
|
def test_sorts_each_check_into_what_held_and_what_broke(self) -> None:
|
|
report = scenario.Report()
|
|
self.assertTrue(report.check(True, "one"))
|
|
self.assertFalse(report.check(False, "two"))
|
|
self.assertEqual((report.held, report.broke), (["one"], ["two"]))
|
|
|
|
|
|
class MachineTest(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
made = tempfile.TemporaryDirectory()
|
|
self.addCleanup(made.cleanup)
|
|
self.folder = pathlib.Path(made.name).resolve()
|
|
self.env_file = self.folder / "jira.env"
|
|
self.env_file.write_text("ATLASSIAN_EMAIL=a@example.com\nATLASSIAN_API_TOKEN=secret\n", encoding="utf-8")
|
|
self.env_file.chmod(0o600)
|
|
self.sandbox = Sandbox("https://acme.atlassian.net", self.env_file, "SBX")
|
|
|
|
def test_writes_settings_that_do_epic_loads_and_that_point_at_the_sandbox(self) -> None:
|
|
home = self.folder / "home"
|
|
machine = scenario.machine_made(home, self.sandbox, pathlib.Path("do-epic"))
|
|
assert not isinstance(machine, Failure), machine
|
|
config = load(home)
|
|
assert not isinstance(config, Failure), config
|
|
self.assertEqual((config.jira_url, config.env_file, config.repo_rule), ("https://acme.atlassian.net", self.env_file, scenario.RULE))
|
|
self.assertEqual((config.finish.transition, config.finish.status) if config.finish else None, ("Done", "Done"))
|
|
|
|
def test_runs_do_epic_with_the_machines_home_and_the_words_and_stdin_given(self) -> None:
|
|
launcher = self.folder / "echo-home"
|
|
launcher.write_text('#!/bin/sh\necho "$HOME $*"; cat\n', encoding="utf-8")
|
|
launcher.chmod(0o755)
|
|
done = scenario.Machine(self.folder, launcher).do_epic("ABC-1", "--file", stdin="detail")
|
|
self.assertEqual((done.returncode, done.stdout), (0, f"{self.folder} ABC-1 --file\ndetail"))
|