Skip to content

Commit

Permalink
Add unit tests for furnish_ci_email_body()
Browse files Browse the repository at this point in the history
Summary: Test existing behavior as well as newly added functionality.

Differential Revision: D58206848

fbshipit-source-id: c9768c9c3400cb541be35dcf02c4835779e60b62
  • Loading branch information
Daniel Xu authored and facebook-github-bot committed Jun 5, 2024
1 parent 6a1cf53 commit a408a61
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/fixtures/test_email_body_conflict.golden
Original file line number Diff line number Diff line change
@@ -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
[email protected].
28 changes: 28 additions & 0 deletions tests/fixtures/test_email_body_failure.golden
Original file line number Diff line number Diff line change
@@ -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
[email protected].
14 changes: 14 additions & 0 deletions tests/fixtures/test_email_body_success.golden
Original file line number Diff line number Diff line change
@@ -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
[email protected].
59 changes: 59 additions & 0 deletions tests/test_branch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

# pyre-unsafe

import importlib.resources
import os
import random
import shutil
import tempfile
Expand All @@ -27,13 +29,16 @@
BRANCH_TTL,
BranchWorker,
create_color_labels,
EmailBodyContext,
furnish_ci_email_body,
has_same_base_different_remote,
HEAD_BASE_SEPARATOR,
temporary_patch_file,
UPSTREAM_REMOTE_NAME,
)
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 (
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)

0 comments on commit a408a61

Please sign in to comment.