|
1 # Copyright (c) 2010 Google Inc. All rights reserved. |
|
2 # |
|
3 # Redistribution and use in source and binary forms, with or without |
|
4 # modification, are permitted provided that the following conditions are |
|
5 # met: |
|
6 # |
|
7 # * Redistributions of source code must retain the above copyright |
|
8 # notice, this list of conditions and the following disclaimer. |
|
9 # * Redistributions in binary form must reproduce the above |
|
10 # copyright notice, this list of conditions and the following disclaimer |
|
11 # in the documentation and/or other materials provided with the |
|
12 # distribution. |
|
13 # * Neither the name of Google Inc. nor the names of its |
|
14 # contributors may be used to endorse or promote products derived from |
|
15 # this software without specific prior written permission. |
|
16 # |
|
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
|
29 import unittest |
|
30 import random |
|
31 |
|
32 from webkitpy.common.system.outputcapture import OutputCapture |
|
33 from webkitpy.tool.bot.sheriff import Sheriff |
|
34 from webkitpy.tool.bot.sheriffircbot import SheriffIRCBot |
|
35 from webkitpy.tool.bot.sheriff_unittest import MockSheriffBot |
|
36 from webkitpy.tool.mocktool import MockTool |
|
37 |
|
38 |
|
39 def run(message): |
|
40 tool = MockTool() |
|
41 tool.ensure_irc_connected(None) |
|
42 bot = SheriffIRCBot(tool, Sheriff(tool, MockSheriffBot())) |
|
43 bot._message_queue.post(["mock_nick", message]) |
|
44 bot.process_pending_messages() |
|
45 |
|
46 |
|
47 class SheriffIRCBotTest(unittest.TestCase): |
|
48 def test_hi(self): |
|
49 random.seed(23324) |
|
50 expected_stderr = 'MOCK: irc.post: "Only you can prevent forest fires." -- Smokey the Bear\n' |
|
51 OutputCapture().assert_outputs(self, run, args=["hi"], expected_stderr=expected_stderr) |
|
52 |
|
53 def test_help(self): |
|
54 expected_stderr = "MOCK: irc.post: mock_nick: Available commands: rollout, hi, help, restart, last-green-revision\n" |
|
55 OutputCapture().assert_outputs(self, run, args=["help"], expected_stderr=expected_stderr) |
|
56 |
|
57 def test_lgr(self): |
|
58 expected_stderr = "MOCK: irc.post: mock_nick: http://trac.webkit.org/changeset/9479\n" |
|
59 OutputCapture().assert_outputs(self, run, args=["last-green-revision"], expected_stderr=expected_stderr) |
|
60 |
|
61 def test_rollout(self): |
|
62 expected_stderr = "MOCK: irc.post: Preparing rollout for r21654...\nMOCK: irc.post: mock_nick: Created rollout: http://example.com/36936\n" |
|
63 OutputCapture().assert_outputs(self, run, args=["rollout 21654 This patch broke the world"], expected_stderr=expected_stderr) |
|
64 |
|
65 def test_rollout_with_r_in_svn_revision(self): |
|
66 expected_stderr = "MOCK: irc.post: Preparing rollout for r21654...\nMOCK: irc.post: mock_nick: Created rollout: http://example.com/36936\n" |
|
67 OutputCapture().assert_outputs(self, run, args=["rollout r21654 This patch broke the world"], expected_stderr=expected_stderr) |
|
68 |
|
69 def test_rollout_bananas(self): |
|
70 expected_stderr = "MOCK: irc.post: mock_nick: Usage: SVN_REVISION REASON\n" |
|
71 OutputCapture().assert_outputs(self, run, args=["rollout bananas"], expected_stderr=expected_stderr) |
|
72 |
|
73 def test_rollout_invalidate_revision(self): |
|
74 expected_stderr = ("MOCK: irc.post: Preparing rollout for r--component=Tools...\n" |
|
75 "MOCK: irc.post: mock_nick: Failed to create rollout patch:\n" |
|
76 "MOCK: irc.post: Invalid svn revision number \"--component=Tools\".\n") |
|
77 OutputCapture().assert_outputs(self, run, |
|
78 args=["rollout " |
|
79 "--component=Tools 21654"], |
|
80 expected_stderr=expected_stderr) |
|
81 |
|
82 def test_rollout_invalidate_reason(self): |
|
83 expected_stderr = ("MOCK: irc.post: Preparing rollout for " |
|
84 "r21654...\nMOCK: irc.post: mock_nick: Failed to " |
|
85 "create rollout patch:\nMOCK: irc.post: The rollout" |
|
86 " reason may not begin with - (\"-bad (Requested " |
|
87 "by mock_nick on #webkit).\").\n") |
|
88 OutputCapture().assert_outputs(self, run, |
|
89 args=["rollout " |
|
90 "21654 -bad"], |
|
91 expected_stderr=expected_stderr) |
|
92 |
|
93 def test_rollout_no_reason(self): |
|
94 expected_stderr = "MOCK: irc.post: mock_nick: Usage: SVN_REVISION REASON\n" |
|
95 OutputCapture().assert_outputs(self, run, args=["rollout 21654"], expected_stderr=expected_stderr) |