blob: c88beaea19f002770c20a58a75147a2436b46927 [file] [log] [blame]
Henrik Kjellandera18a3bf2017-09-15 11:19:10 +02001#!/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
charujain9893e252017-09-14 13:33:22 +020011import unittest
12
13import PRESUBMIT
14from presubmit_test_mocks import MockInputApi, MockOutputApi
15
16
17class 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 Lemur6d01f6d2017-09-14 17:02:01 +020023 mock_output_api)
charujain9893e252017-09-14 13:33:22 +020024 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 Lemur6d01f6d2017-09-14 17:02:01 +020031 mock_output_api)
charujain9893e252017-09-14 13:33:22 +020032 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 Lemur6d01f6d2017-09-14 17:02:01 +020043 mock_output_api)
charujain9893e252017-09-14 13:33:22 +020044 self.assertEqual(0, len(errors))
45
46
47if __name__ == '__main__':
48 unittest.main()