Test base_of and a failed ls-remote of chunk-pr push
This commit is contained in:
@@ -12,7 +12,7 @@ import unittest
|
|||||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||||
|
|
||||||
from chunk_pr.approval import awaited
|
from chunk_pr.approval import awaited
|
||||||
from chunk_pr.main import cleaned, merged, QUEUE, step, turn, USAGE
|
from chunk_pr.main import base_of, Base, cleaned, merged, QUEUE, step, turn, USAGE
|
||||||
from failure import Failure
|
from failure import Failure
|
||||||
from test_env import isolated_env
|
from test_env import isolated_env
|
||||||
from project_config.settings import ProjectConfig
|
from project_config.settings import ProjectConfig
|
||||||
@@ -22,9 +22,9 @@ from forge.reviews import THREADS
|
|||||||
TOOL = pathlib.Path(__file__).resolve().parents[1] / "chunk-pr"
|
TOOL = pathlib.Path(__file__).resolve().parents[1] / "chunk-pr"
|
||||||
GITHUB = "git@github.com:me/project.git"
|
GITHUB = "git@github.com:me/project.git"
|
||||||
GITEA = "ssh://git@gitea.example.org:22/me/project.git"
|
GITEA = "ssh://git@gitea.example.org:22/me/project.git"
|
||||||
HEAD = "c0ffee"
|
HEAD = "c0ffee" * 7
|
||||||
PUSH = ["git", "push", "--quiet", "--set-upstream", "origin", "item-7"]
|
PUSH = ["git", "push", "--quiet", "--set-upstream", "origin", "item-7"]
|
||||||
OLD = "badc0de"
|
OLD = "badc0de" * 6
|
||||||
OLD_HEAD = ["git", "ls-remote", "origin", "refs/heads/item-7"]
|
OLD_HEAD = ["git", "ls-remote", "origin", "refs/heads/item-7"]
|
||||||
GH_LIST = ["gh", "pr", "list", "--head", "item-7", "--json", "number,headRefOid,isCrossRepository", "--template", "{{range .}}{{.number}}\t{{.headRefOid}}\t{{.isCrossRepository}}\n{{end}}"]
|
GH_LIST = ["gh", "pr", "list", "--head", "item-7", "--json", "number,headRefOid,isCrossRepository", "--template", "{{range .}}{{.number}}\t{{.headRefOid}}\t{{.isCrossRepository}}\n{{end}}"]
|
||||||
TEA_LIST = ["tea", "api", "repos/{owner}/{repo}/pulls?state=open&limit=50"]
|
TEA_LIST = ["tea", "api", "repos/{owner}/{repo}/pulls?state=open&limit=50"]
|
||||||
@@ -1090,6 +1090,17 @@ class EpicBranch(unittest.TestCase):
|
|||||||
self.assertIn("awaits a person's merge", str(done))
|
self.assertIn("awaits a person's merge", str(done))
|
||||||
self.assertFalse(any("merge" in command[1:4] for command in checkout.acted() if command[0] != "git"), checkout.acted())
|
self.assertFalse(any("merge" in command[1:4] for command in checkout.acted() if command[0] != "git"), checkout.acted())
|
||||||
|
|
||||||
|
def test_a_branch_whose_base_git_does_not_record_merges_into_the_default_branch(self):
|
||||||
|
self.assertEqual(base_of("item-7", self.unrecorded), Base("main", False))
|
||||||
|
self.assertEqual(base_of("item-7", self.recorded("main")), Base("main", False))
|
||||||
|
self.assertEqual(base_of("item-7", self.recorded("ABC-1")), Base("ABC-1", True))
|
||||||
|
|
||||||
|
def unrecorded(self, command: list[str]) -> str | Failure:
|
||||||
|
return Failure("git config: exit 1") if command[:3] == ["git", "config", "--get"] else "origin/main\n"
|
||||||
|
|
||||||
|
def recorded(self, base: str) -> Run:
|
||||||
|
return lambda command: f"{base}\n" if command[:3] == ["git", "config", "--get"] else "origin/main\n"
|
||||||
|
|
||||||
def test_merge_fails_naming_both_branches_where_the_forge_merges_the_pull_request_into_another_branch_than_the_checkout_records(self):
|
def test_merge_fails_naming_both_branches_where_the_forge_merges_the_pull_request_into_another_branch_than_the_checkout_records(self):
|
||||||
for origin in (GITHUB, GITEA):
|
for origin in (GITHUB, GITEA):
|
||||||
with self.subTest(origin):
|
with self.subTest(origin):
|
||||||
@@ -1219,6 +1230,12 @@ class EpicBranch(unittest.TestCase):
|
|||||||
self.assertEqual(step(["push"], checkout, checkout.config, sleep=slept.append), "Pushed item-7.")
|
self.assertEqual(step(["push"], checkout, checkout.config, sleep=slept.append), "Pushed item-7.")
|
||||||
self.assertEqual(slept, [])
|
self.assertEqual(slept, [])
|
||||||
|
|
||||||
|
def test_a_push_whose_old_head_cannot_be_read_pushes_nothing(self):
|
||||||
|
checkout = self.checkout()
|
||||||
|
checkout.answers[tuple(OLD_HEAD)] = Failure("git ls-remote: no network")
|
||||||
|
self.assertEqual(step(["push"], checkout, checkout.config), Failure("git ls-remote: no network"))
|
||||||
|
self.assertNotIn(PUSH, checkout.ran)
|
||||||
|
|
||||||
def test_a_failed_push_asks_for_no_review(self):
|
def test_a_failed_push_asks_for_no_review(self):
|
||||||
checkout = self.checkout()
|
checkout = self.checkout()
|
||||||
checkout.answers[tuple(PUSH)] = Failure("git push: rejected")
|
checkout.answers[tuple(PUSH)] = Failure("git push: rejected")
|
||||||
|
|||||||
Reference in New Issue
Block a user