Files
mongo/buildscripts/tests/test_validate_commit_message.py
Juan Gu 855dfadef0 SERVER-94077 Use isort in Ruff configs (#27865)
GitOrigin-RevId: e793d662774ccd3ab6c3f356c2287cf1f7ff9805
2024-10-10 19:33:49 +00:00

71 lines
3.0 KiB
Python

"""Unit tests for the evergreen_task_timeout script."""
import unittest
from git import Commit, Repo
from buildscripts.validate_commit_message import is_valid_commit
class ValidateCommitMessageTest(unittest.TestCase):
def test_valid(self):
fake_repo = Repo()
messages = [
Commit(repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message="SERVER-44338"),
Commit(repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message='Revert "SERVER-60'),
Commit(
repo=fake_repo,
binsha=b"deadbeefdeadbeefdead",
message="Import wiredtiger: 58115abb6fbb3c1cc7bfd087d41a47347bce9a69 from branch mongodb-4.4",
),
Commit(
repo=fake_repo,
binsha=b"deadbeefdeadbeefdead",
message='Revert "Import wiredtiger: 58115abb6fbb3c1cc7bfd087d41a47347bce9a69 from branch mongodb-4.4"',
),
Commit(
repo=fake_repo,
binsha=b"deadbeefdeadbeefdead",
message="SERVER-44338 blablablalbabla\nmultiline message\nasdfasdf",
),
]
self.assertTrue(all(is_valid_commit(message) for message in messages))
def test_invalid(self):
fake_repo = Repo()
messages = [
Commit(
repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message="SERVER-"
), # missing number
Commit(
repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message="Revert SERVER-60"
), # missing quote before SERVER
Commit(repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message=""), # empty value
Commit(
repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message="nonsense"
), # nonsense value
Commit(
repo=fake_repo,
binsha=b"deadbeefdeadbeefdead",
message="SERVER-123 asdf\nhttps://spruce.mongodb.com",
), # Contains some banned strings
Commit(
repo=fake_repo,
binsha=b"deadbeefdeadbeefdead",
message="SERVER-123 asdf\nhttps://evergreen.mongodb.com",
), # Contains some banned strings
Commit(
repo=fake_repo,
binsha=b"deadbeefdeadbeefdead",
message="SERVER-123 asdf\nAnything in this description will be included in the commit message. Replace or delete this text before merging. Add links to testing in the comments of the PR.",
), # Contains some banned strings
Commit(
repo=fake_repo,
binsha=b"deadbeefdeadbeefdead",
message="SERVER-123 asdf\nAnything\n\n in this description will be included in the commit message.\nReplace or delete this text before merging. Add links to testing in the\ncomments of the PR.",
), # Contains some banned strings with extra newlines
]
self.assertTrue(all(not is_valid_commit(message) for message in messages))