blob: 84821595db0dfad0727b5cbb3f4bca9fff0fdcac [file] [log] [blame]
Gaurav Shah298aa372014-01-31 09:27:24 -08001#!/usr/bin/python
2# Copyright (c) 2014 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
6"""Unit tests for the cbuildbot program"""
7
8import os
9import sys
10
11sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(
12 os.path.abspath(__file__)))))
13
Don Garrett88b8d782014-05-13 17:30:55 -070014from chromite.cbuildbot import constants
Gaurav Shah298aa372014-01-31 09:27:24 -080015from chromite.lib import cros_test_lib
16from chromite.scripts import cbuildbot
17
18
19class IsDistributedBuilderTest(cros_test_lib.TestCase):
20 """Test for cbuildbot._IsDistributedBuilder."""
21
22 # pylint: disable=W0212
23 def testIsDistributedBuilder(self):
24 """Tests for _IsDistributedBuilder() under various configurations."""
25 parser = cbuildbot._CreateParser()
26 argv = ['x86-generic-paladin']
27 (options, _) = cbuildbot._ParseCommandLine(parser, argv)
28 options.buildbot = False
29 options.pre_cq = False
30
31 build_config = dict(pre_cq=False,
32 manifest_version=False)
33 chrome_rev = None
34
35 def _TestConfig(expected):
36 self.assertEquals(expected,
37 cbuildbot._IsDistributedBuilder(
38 options=options,
39 chrome_rev=chrome_rev,
40 build_config=build_config))
41
42 # Default options.
43 _TestConfig(False)
44
45 # In Pre-CQ mode, we run as as a distributed builder.
46 options.pre_cq = True
47 _TestConfig(True)
48
49 options.pre_cq = False
50 build_config['pre_cq'] = True
51 _TestConfig(True)
52
53 build_config['pre_cq'] = False
54 build_config['manifest_version'] = True
55 # Not running in buildbot mode even though manifest_version=True.
56 _TestConfig(False)
57 options.buildbot = True
58 _TestConfig(True)
59
60 for chrome_rev in (constants.CHROME_REV_TOT,
61 constants.CHROME_REV_LOCAL,
62 constants.CHROME_REV_SPEC):
63 _TestConfig(False)
64
65
66if __name__ == '__main__':
67 cros_test_lib.main()