diff --git a/tests/fixtures/test_email_body_conflict.golden b/tests/fixtures/test_email_body_conflict.golden new file mode 100644 index 0000000..393a362 --- /dev/null +++ b/tests/fixtures/test_email_body_conflict.golden @@ -0,0 +1,15 @@ +Dear patch submitter, + +CI has tested the following submission: +Status: CONFLICT +Name: [bpf-next] Conflicting patchset +Patchwork: https://patchwork.com/conflict +PR: https://github.com/conflict + +Please rebase your submission onto the most recent upstream change and resubmit +the patch to get it tested again. + + +Please note: this email is coming from an unmonitored mailbox. If you have +questions or feedback, please reach out to the Meta Kernel CI team at +kernel-ci@meta.com. diff --git a/tests/fixtures/test_email_body_failure.golden b/tests/fixtures/test_email_body_failure.golden new file mode 100644 index 0000000..611ce27 --- /dev/null +++ b/tests/fixtures/test_email_body_failure.golden @@ -0,0 +1,28 @@ +Dear patch submitter, + +CI has tested the following submission: +Status: FAILURE +Name: [bpf] Failing patchset +Patchwork: https://patchwork.com/failure +Matrix: https://github.com/failure + +Failed jobs: +test_progs-x86_64-gcc: https://job1.com +test_progs_no_alu32-x86_64-gcc: https://job2.com + +First test_progs failure (test_progs-x86_64-gcc): +#53 cgrp_local_storage +cgrp2_local_storage:PASS:join_cgroup /cgrp_local_storage 0 nsec +#53/2 cgrp_local_storage/attach_cgroup +test_attach_cgroup:PASS:skel_open 0 nsec +test_attach_cgroup:PASS:prog_attach 0 nsec +test_attach_cgroup:PASS:prog_attach 0 nsec +test_attach_cgroup:PASS:prog_attach 0 nsec +test_attach_cgroup:PASS:start_server 0 nsec +test_attach_cgroup:PASS:connect_to_fd 0 nsec +test_attach_cgroup:FAIL:map_lookup(socket_cookies) unexpected error: -2 (errno 2) + + +Please note: this email is coming from an unmonitored mailbox. If you have +questions or feedback, please reach out to the Meta Kernel CI team at +kernel-ci@meta.com. diff --git a/tests/fixtures/test_email_body_success.golden b/tests/fixtures/test_email_body_success.golden new file mode 100644 index 0000000..2b260fe --- /dev/null +++ b/tests/fixtures/test_email_body_success.golden @@ -0,0 +1,14 @@ +Dear patch submitter, + +CI has tested the following submission: +Status: SUCCESS +Name: [bpf] Successfull patchset +Patchwork: https://patchwork.com/success +Matrix: https://github.com/success + +No further action is necessary on your part. + + +Please note: this email is coming from an unmonitored mailbox. If you have +questions or feedback, please reach out to the Meta Kernel CI team at +kernel-ci@meta.com. diff --git a/tests/test_branch_worker.py b/tests/test_branch_worker.py index 2c7ed47..6b55ebb 100644 --- a/tests/test_branch_worker.py +++ b/tests/test_branch_worker.py @@ -6,6 +6,8 @@ # pyre-unsafe +import importlib.resources +import os import random import shutil import tempfile @@ -27,6 +29,8 @@ BRANCH_TTL, BranchWorker, create_color_labels, + EmailBodyContext, + furnish_ci_email_body, has_same_base_different_remote, HEAD_BASE_SEPARATOR, temporary_patch_file, @@ -34,6 +38,7 @@ ) from kernel_patches_daemon.github_logs import DefaultGithubLogExtractor from kernel_patches_daemon.patchwork import Series, Subject +from kernel_patches_daemon.status import Status from munch import Munch, munchify from tests.common.patchwork_mock import ( @@ -91,6 +96,12 @@ } +def read_fixture(filepath: str) -> str: + with importlib.resources.path(__package__, "fixtures") as base: + with open(os.path.join(base, "fixtures", filepath)) as f: + return f.read() + + class BranchWorkerMock(BranchWorker): def __init__(self, *args: Any, **kwargs: Any) -> None: presets = { @@ -968,3 +979,51 @@ async def test_applied_all_case_insensitive(self, m: aioresponses): in_2 = ALREADY_MERGED_LOOKBACK + 34 series = await self._get_series(m, [f"commit {in_1}", f"[tag] COMMIT {in_2}"]) self.assertTrue(await _series_already_applied(self.repo, series)) + + +class TestEmailNotificationBody(unittest.TestCase): + # Always show full diff on string match failures + maxDiff = None + + def test_email_body_success(self): + expected = read_fixture("test_email_body_success.golden") + + ctx = EmailBodyContext( + status=Status.SUCCESS, + submission_name="[bpf] Successfull patchset", + patchwork_url="https://patchwork.com/success", + github_url="https://github.com/success", + inline_logs="", + ) + body = furnish_ci_email_body(ctx) + + self.assertEqual(expected, body) + + def test_email_body_failure(self): + inline_logs = read_fixture("test_inline_email_text_multiple.golden") + expected = read_fixture("test_email_body_failure.golden") + + ctx = EmailBodyContext( + status=Status.FAILURE, + submission_name="[bpf] Failing patchset", + patchwork_url="https://patchwork.com/failure", + github_url="https://github.com/failure", + inline_logs=inline_logs, + ) + body = furnish_ci_email_body(ctx) + + self.assertEqual(expected, body) + + def test_email_body_conflict(self): + expected = read_fixture("test_email_body_conflict.golden") + + ctx = EmailBodyContext( + status=Status.CONFLICT, + submission_name="[bpf-next] Conflicting patchset", + patchwork_url="https://patchwork.com/conflict", + github_url="https://github.com/conflict", + inline_logs="", + ) + body = furnish_ci_email_body(ctx) + + self.assertEqual(expected, body)