Henrik Kjellander | a18a3bf | 2017-09-15 11:19:10 +0200 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license |
| 6 | # that can be found in the LICENSE file in the root of the source |
| 7 | # tree. An additional intellectual property rights grant can be found |
| 8 | # in the file PATENTS. All contributing project authors may |
| 9 | # be found in the AUTHORS file in the root of the source tree. |
| 10 | |
charujain | 9893e25 | 2017-09-14 13:33:22 +0200 | [diff] [blame] | 11 | import unittest |
| 12 | |
| 13 | import PRESUBMIT |
| 14 | from presubmit_test_mocks import MockInputApi, MockOutputApi |
| 15 | |
| 16 | |
| 17 | class CheckBugEntryField(unittest.TestCase): |
| 18 | def testCommitMessageBugEntryWithNoError(self): |
| 19 | mock_input_api = MockInputApi() |
| 20 | mock_output_api = MockOutputApi() |
| 21 | mock_input_api.change.BUG = 'webrtc:1234' |
| 22 | errors = PRESUBMIT.CheckCommitMessageBugEntry(mock_input_api, |
Edward Lemur | 6d01f6d | 2017-09-14 17:02:01 +0200 | [diff] [blame] | 23 | mock_output_api) |
charujain | 9893e25 | 2017-09-14 13:33:22 +0200 | [diff] [blame] | 24 | self.assertEqual(0, len(errors)) |
| 25 | |
| 26 | def testCommitMessageBugEntryReturnError(self): |
| 27 | mock_input_api = MockInputApi() |
| 28 | mock_output_api = MockOutputApi() |
| 29 | mock_input_api.change.BUG = 'webrtc:1234,webrtc=4321' |
| 30 | errors = PRESUBMIT.CheckCommitMessageBugEntry(mock_input_api, |
Edward Lemur | 6d01f6d | 2017-09-14 17:02:01 +0200 | [diff] [blame] | 31 | mock_output_api) |
charujain | 9893e25 | 2017-09-14 13:33:22 +0200 | [diff] [blame] | 32 | self.assertEqual(1, len(errors)) |
| 33 | self.assertEqual(('Bogus BUG entry: webrtc=4321. Please specify' |
| 34 | ' the issue tracker prefix and the issue number,' |
| 35 | ' separated by a colon, e.g. webrtc:123 or' |
| 36 | ' chromium:12345.'), str(errors[0])) |
| 37 | |
| 38 | def testCommitMessageBugEntryIsNone(self): |
| 39 | mock_input_api = MockInputApi() |
| 40 | mock_output_api = MockOutputApi() |
| 41 | mock_input_api.change.BUG = 'None' |
| 42 | errors = PRESUBMIT.CheckCommitMessageBugEntry(mock_input_api, |
Edward Lemur | 6d01f6d | 2017-09-14 17:02:01 +0200 | [diff] [blame] | 43 | mock_output_api) |
charujain | 9893e25 | 2017-09-14 13:33:22 +0200 | [diff] [blame] | 44 | self.assertEqual(0, len(errors)) |
| 45 | |
| 46 | |
| 47 | if __name__ == '__main__': |
| 48 | unittest.main() |