blob: 177c9eee0f7004e48d26595add637d5f3f230b9f [file] [log] [blame]
Gaurav Shah298aa372014-01-31 09:27:24 -08001# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Unit tests for the cbuildbot program"""
6
Mike Frysinger383367e2014-09-16 15:06:17 -04007from __future__ import print_function
8
Don Garrett4af20982015-05-29 19:02:23 -07009from chromite.cbuildbot import config_lib_unittest
Don Garrett88b8d782014-05-13 17:30:55 -070010from chromite.cbuildbot import constants
Gaurav Shah298aa372014-01-31 09:27:24 -080011from chromite.lib import cros_test_lib
12from chromite.scripts import cbuildbot
13
14
15class IsDistributedBuilderTest(cros_test_lib.TestCase):
16 """Test for cbuildbot._IsDistributedBuilder."""
17
18 # pylint: disable=W0212
19 def testIsDistributedBuilder(self):
20 """Tests for _IsDistributedBuilder() under various configurations."""
Don Garrett4af20982015-05-29 19:02:23 -070021 site_config = config_lib_unittest.MockSiteConfig()
22
Gaurav Shah298aa372014-01-31 09:27:24 -080023 parser = cbuildbot._CreateParser()
24 argv = ['x86-generic-paladin']
Don Garrett4af20982015-05-29 19:02:23 -070025 (options, _) = cbuildbot._ParseCommandLine(parser, argv, site_config)
Gaurav Shah298aa372014-01-31 09:27:24 -080026 options.buildbot = False
27 options.pre_cq = False
28
29 build_config = dict(pre_cq=False,
30 manifest_version=False)
31 chrome_rev = None
32
33 def _TestConfig(expected):
34 self.assertEquals(expected,
35 cbuildbot._IsDistributedBuilder(
36 options=options,
37 chrome_rev=chrome_rev,
38 build_config=build_config))
39
40 # Default options.
41 _TestConfig(False)
42
43 # In Pre-CQ mode, we run as as a distributed builder.
44 options.pre_cq = True
45 _TestConfig(True)
46
47 options.pre_cq = False
48 build_config['pre_cq'] = True
49 _TestConfig(True)
50
51 build_config['pre_cq'] = False
52 build_config['manifest_version'] = True
53 # Not running in buildbot mode even though manifest_version=True.
54 _TestConfig(False)
55 options.buildbot = True
56 _TestConfig(True)
57
58 for chrome_rev in (constants.CHROME_REV_TOT,
59 constants.CHROME_REV_LOCAL,
60 constants.CHROME_REV_SPEC):
61 _TestConfig(False)