Home | History | Annotate | Download | only in bot
      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: whois, hi, last-green-revision, rollout, restart, help\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_multi_rollout(self):
     66         expected_stderr = "MOCK: irc.post: Preparing rollout for r21654, r21655, and r21656...\nMOCK: irc.post: mock_nick: Created rollout: http://example.com/36936\n"
     67         OutputCapture().assert_outputs(self, run, args=["rollout 21654 21655 21656 This 21654 patch broke the world"], expected_stderr=expected_stderr)
     68 
     69     def test_rollout_with_r_in_svn_revision(self):
     70         expected_stderr = "MOCK: irc.post: Preparing rollout for r21654...\nMOCK: irc.post: mock_nick: Created rollout: http://example.com/36936\n"
     71         OutputCapture().assert_outputs(self, run, args=["rollout r21654 This patch broke the world"], expected_stderr=expected_stderr)
     72 
     73     def test_multi_rollout_with_r_in_svn_revision(self):
     74         expected_stderr = "MOCK: irc.post: Preparing rollout for r21654, r21655, and r21656...\nMOCK: irc.post: mock_nick: Created rollout: http://example.com/36936\n"
     75         OutputCapture().assert_outputs(self, run, args=["rollout r21654 21655 r21656 This r21654 patch broke the world"], expected_stderr=expected_stderr)
     76 
     77     def test_rollout_bananas(self):
     78         expected_stderr = "MOCK: irc.post: mock_nick: Usage: SVN_REVISION [SVN_REVISIONS] REASON\n"
     79         OutputCapture().assert_outputs(self, run, args=["rollout bananas"], expected_stderr=expected_stderr)
     80 
     81     def test_rollout_invalidate_revision(self):
     82         expected_stderr = ("MOCK: irc.post: Preparing rollout for r--component=Tools...\n"
     83                            "MOCK: irc.post: mock_nick: Failed to create rollout patch:\n"
     84                            "MOCK: irc.post: Invalid svn revision number \"--component=Tools\".\n")
     85         OutputCapture().assert_outputs(self, run,
     86                                        args=["rollout "
     87                                              "--component=Tools 21654"],
     88                                        expected_stderr=expected_stderr)
     89 
     90     def test_rollout_invalidate_reason(self):
     91         expected_stderr = ("MOCK: irc.post: Preparing rollout for "
     92                            "r21654...\nMOCK: irc.post: mock_nick: Failed to "
     93                            "create rollout patch:\nMOCK: irc.post: The rollout"
     94                            " reason may not begin with - (\"-bad (Requested "
     95                            "by mock_nick on #webkit).\").\n")
     96         OutputCapture().assert_outputs(self, run,
     97                                        args=["rollout "
     98                                              "21654 -bad"],
     99                                        expected_stderr=expected_stderr)
    100 
    101     def test_multi_rollout_invalidate_reason(self):
    102         expected_stderr = ("MOCK: irc.post: Preparing rollout for "
    103                            "r21654, r21655, and r21656...\nMOCK: irc.post: mock_nick: Failed to "
    104                            "create rollout patch:\nMOCK: irc.post: The rollout"
    105                            " reason may not begin with - (\"-bad (Requested "
    106                            "by mock_nick on #webkit).\").\n")
    107         OutputCapture().assert_outputs(self, run,
    108                                        args=["rollout "
    109                                              "21654 21655 r21656 -bad"],
    110                                        expected_stderr=expected_stderr)
    111 
    112     def test_rollout_no_reason(self):
    113         expected_stderr = "MOCK: irc.post: mock_nick: Usage: SVN_REVISION [SVN_REVISIONS] REASON\n"
    114         OutputCapture().assert_outputs(self, run, args=["rollout 21654"], expected_stderr=expected_stderr)
    115 
    116     def test_multi_rollout_no_reason(self):
    117         expected_stderr = "MOCK: irc.post: mock_nick: Usage: SVN_REVISION [SVN_REVISIONS] REASON\n"
    118         OutputCapture().assert_outputs(self, run, args=["rollout 21654 21655 r21656"], expected_stderr=expected_stderr)
    119