blob: f3ae288914a5cd54d8a16e175234f1a69f830900 [file] [log] [blame]
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08001# -*- coding: utf-8 -*-
Kuang-che Wue41e0062017-09-01 19:04:14 +08002# Copyright 2017 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Test bisect_git script."""
6
7from __future__ import print_function
Kuang-che Wue80bb872018-11-15 19:45:25 +08008import shutil
9import tempfile
Kuang-che Wue41e0062017-09-01 19:04:14 +080010import unittest
Kuang-che Wu23192ad2020-03-11 18:12:46 +080011from unittest import mock
Kuang-che Wue41e0062017-09-01 19:04:14 +080012
Kuang-che Wu2526a672019-09-10 16:23:59 +080013from bisect_kit import bisector_cli
Kuang-che Wue80bb872018-11-15 19:45:25 +080014from bisect_kit import git_util_test
Kuang-che Wu3d37dbf2020-04-15 00:22:01 +080015from bisect_kit import testing
Kuang-che Wue41e0062017-09-01 19:04:14 +080016import bisect_git
17
18
19@mock.patch('bisect_kit.common.config_logging', mock.Mock())
20class TestGitDomain(unittest.TestCase):
21 """Test GitDomain class."""
22
23 def setUp(self):
Kuang-che Wub6506872020-09-14 22:10:03 +080024 self.session_base_patcher = testing.SessionBasePatcher()
25 self.session_base_patcher.patch()
Kuang-che Wue80bb872018-11-15 19:45:25 +080026 self.git_repo = tempfile.mkdtemp()
27 self.git = git_util_test.GitOperation(self.git_repo)
28 self.git.init()
29
30 def tearDown(self):
31 shutil.rmtree(self.git_repo)
Kuang-che Wub6506872020-09-14 22:10:03 +080032 self.session_base_patcher.reset()
Kuang-che Wue41e0062017-09-01 19:04:14 +080033
34 def test_basic(self):
35 """Tests basic functionality."""
Kuang-che Wu2526a672019-09-10 16:23:59 +080036 bisector = bisector_cli.BisectorCommandLine(bisect_git.GitDomain)
Kuang-che Wue41e0062017-09-01 19:04:14 +080037
Kuang-che Wu5e7c9b02019-01-03 21:16:01 +080038 self.git.create_commits(10)
39 commits = self.git.commits
40 old, new = commits[1], commits[-1]
Kuang-che Wue41e0062017-09-01 19:04:14 +080041
Kuang-che Wu5e7c9b02019-01-03 21:16:01 +080042 bisector.main('init', '--old', old, '--new', new, '--git_repo',
43 self.git_repo)
Kuang-che Wue41e0062017-09-01 19:04:14 +080044
Kuang-che Wu88518882017-09-22 16:57:25 +080045 bisector.main('config', 'switch', 'true')
46 bisector.main('config', 'eval', 'true')
Kuang-che Wue41e0062017-09-01 19:04:14 +080047
48 with mock.patch('bisect_kit.util.Popen') as mock_popen:
49 run_mocks = [mock.Mock(), mock.Mock()]
50 run_mocks[0].wait.return_value = 0
51 run_mocks[1].wait.return_value = 0
52 mock_popen.side_effect = run_mocks
53 bisector.main('run', old)
54
55 switch_env = mock_popen.call_args_list[0][1]['env']
56 self.assertEqual(switch_env.get('GIT_REV'), old)
57 self.assertEqual(switch_env.get('GIT_REPO'), self.git_repo)
58
59 eval_env = mock_popen.call_args_list[1][1]['env']
60 self.assertEqual(eval_env.get('GIT_REV'), old)
61 self.assertEqual(eval_env.get('GIT_REPO'), self.git_repo)
62 bisector.main('view')
63
64
65if __name__ == '__main__':
66 unittest.main()