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