2019-12-06 16:59:35 +00:00
|
|
|
"""Unit tests for the evergreen_task_timeout script."""
|
2020-04-28 20:46:00 -04:00
|
|
|
|
2019-12-06 16:59:35 +00:00
|
|
|
import unittest
|
2020-04-28 20:46:00 -04:00
|
|
|
from mock import MagicMock, patch
|
2019-12-06 16:59:35 +00:00
|
|
|
|
2020-04-28 20:46:00 -04:00
|
|
|
from buildscripts.validate_commit_message import main, STATUS_OK, STATUS_ERROR, GIT_SHOW_COMMAND
|
2019-12-06 16:59:35 +00:00
|
|
|
|
|
|
|
|
# pylint: disable=missing-docstring,no-self-use
|
|
|
|
|
|
|
|
|
|
INVALID_MESSAGES = [
|
|
|
|
|
[""], # You must provide a message
|
|
|
|
|
["RevertEVG-1"], # revert and ticket must be formatted
|
|
|
|
|
["revert EVG-1"], # revert must be capitalized
|
|
|
|
|
["This is not a valid message"], # message must be valid
|
|
|
|
|
["Fix lint plus extras is not a valid message"], # Fix lint is strict
|
|
|
|
|
]
|
|
|
|
|
|
2019-12-09 11:45:50 +00:00
|
|
|
NS = "buildscripts.validate_commit_message"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ns(relative_name): # pylint: disable=invalid-name
|
2020-04-28 20:46:00 -04:00
|
|
|
"""Return a full name from a name relative to the test module"s name space."""
|
2019-12-09 11:45:50 +00:00
|
|
|
return NS + "." + relative_name
|
|
|
|
|
|
2019-12-06 16:59:35 +00:00
|
|
|
|
2020-04-28 20:46:00 -04:00
|
|
|
class ValidateCommitMessageTest(unittest.TestCase):
|
|
|
|
|
def test_valid(self):
|
2019-12-06 16:59:35 +00:00
|
|
|
messages = [
|
2020-04-28 20:46:00 -04:00
|
|
|
["Fix lint"],
|
|
|
|
|
["EVG-1"], # Test valid projects with various number lengths
|
|
|
|
|
["SERVER-20"],
|
|
|
|
|
["WT-300"],
|
|
|
|
|
["SERVER-44338"],
|
|
|
|
|
["Revert EVG-5"],
|
|
|
|
|
["Revert SERVER-60"],
|
|
|
|
|
["Revert WT-700"],
|
|
|
|
|
["Revert 'SERVER-8000"],
|
|
|
|
|
['Revert "SERVER-90000'],
|
|
|
|
|
["Import wiredtiger: 58115abb6fbb3c1cc7bfd087d41a47347bce9a69 from branch mongodb-4.4"],
|
|
|
|
|
["Import tools: 58115abb6fbb3c1cc7bfd087d41a47347bce9a69 from branch mongodb-4.4"]
|
2020-01-23 17:52:51 +00:00
|
|
|
]
|
2020-03-02 14:48:15 +00:00
|
|
|
|
2020-04-28 20:46:00 -04:00
|
|
|
self.assertTrue(all(main(message) == STATUS_OK for message in messages))
|
2020-03-02 14:48:15 +00:00
|
|
|
|
2020-04-28 20:46:00 -04:00
|
|
|
def test_private(self):
|
|
|
|
|
self.assertEqual(main(["XYZ-1"]), STATUS_ERROR)
|
2020-03-02 14:48:15 +00:00
|
|
|
|
2020-04-28 20:46:00 -04:00
|
|
|
def test_catch_all(self):
|
|
|
|
|
self.assertTrue(all(main(message) == STATUS_ERROR for message in INVALID_MESSAGES))
|
2020-03-02 14:48:15 +00:00
|
|
|
|
2020-04-28 20:46:00 -04:00
|
|
|
def test_ignore_warnings(self):
|
|
|
|
|
self.assertTrue(all(main(["-i"] + message) == STATUS_OK for message in INVALID_MESSAGES))
|
2020-03-02 14:48:15 +00:00
|
|
|
|
2020-04-28 20:46:00 -04:00
|
|
|
def test_last_git_commit_success(self):
|
|
|
|
|
with patch(
|
|
|
|
|
ns("subprocess.check_output"),
|
|
|
|
|
return_value=bytearray('SERVER-1111 this is a test', 'utf-8')) as check_output_mock:
|
|
|
|
|
self.assertEqual(main([]), 0)
|
|
|
|
|
check_output_mock.assert_called_with(GIT_SHOW_COMMAND)
|