Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 1 | # 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 Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 7 | from __future__ import print_function |
| 8 | |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 9 | from chromite.cbuildbot import config_lib_unittest |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 10 | from chromite.cbuildbot import constants |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 11 | from chromite.lib import cros_test_lib |
| 12 | from chromite.scripts import cbuildbot |
| 13 | |
| 14 | |
| 15 | class 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 Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 21 | site_config = config_lib_unittest.MockSiteConfig() |
| 22 | |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 23 | parser = cbuildbot._CreateParser() |
| 24 | argv = ['x86-generic-paladin'] |
Don Garrett | 4af2098 | 2015-05-29 19:02:23 -0700 | [diff] [blame] | 25 | (options, _) = cbuildbot._ParseCommandLine(parser, argv, site_config) |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 26 | 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) |