blob: 2ecfb83fbb942cceef8c7ed87c8bcb3e44593473 [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
Aviv Keshetb7519e12016-10-04 00:50:00 -07007from chromite.lib import constants
Gaurav Shah298aa372014-01-31 09:27:24 -08008from chromite.lib import cros_test_lib
9from chromite.scripts import cbuildbot
10
11
Don Garrettb85658c2015-06-30 19:07:22 -070012# pylint: disable=protected-access
13
14
Gaurav Shah298aa372014-01-31 09:27:24 -080015class IsDistributedBuilderTest(cros_test_lib.TestCase):
16 """Test for cbuildbot._IsDistributedBuilder."""
17
Mike Frysinger27e21b72018-07-12 14:20:21 -040018 # pylint: disable=protected-access
Gaurav Shah298aa372014-01-31 09:27:24 -080019 def testIsDistributedBuilder(self):
20 """Tests for _IsDistributedBuilder() under various configurations."""
21 parser = cbuildbot._CreateParser()
Don Garrett211df8c2017-09-06 13:33:02 -070022 argv = ['--buildroot', '/foo', 'amd64-generic-paladin']
Mike Frysinger80bba8a2017-08-18 15:28:36 -040023 options = cbuildbot.ParseCommandLine(parser, argv)
Gaurav Shah298aa372014-01-31 09:27:24 -080024 options.buildbot = False
Gaurav Shah298aa372014-01-31 09:27:24 -080025
Mike Frysingerc3e88fa2020-03-26 02:49:02 -040026 build_config = dict(manifest_version=False)
Gaurav Shah298aa372014-01-31 09:27:24 -080027 chrome_rev = None
28
29 def _TestConfig(expected):
Mike Frysinger2d589a12019-08-25 14:15:12 -040030 self.assertEqual(expected,
31 cbuildbot._IsDistributedBuilder(
32 options=options,
33 chrome_rev=chrome_rev,
34 build_config=build_config))
Gaurav Shah298aa372014-01-31 09:27:24 -080035
36 # Default options.
37 _TestConfig(False)
38
Gaurav Shah298aa372014-01-31 09:27:24 -080039 build_config['manifest_version'] = True
40 # Not running in buildbot mode even though manifest_version=True.
41 _TestConfig(False)
42 options.buildbot = True
43 _TestConfig(True)
44
45 for chrome_rev in (constants.CHROME_REV_TOT,
46 constants.CHROME_REV_LOCAL,
47 constants.CHROME_REV_SPEC):
48 _TestConfig(False)
Gregory Meinke5a25ac72019-01-31 13:20:51 -070049
50
51class PostsubmitBuilderTest(cros_test_lib.TestCase):
52 """Test for special parameters for ChromeOS Findit Integration."""
53
54 def testBuildPackages(self):
55 parser = cbuildbot.CreateParser()
56 argv = ['--buildroot', '/foo', '--buildbot',
Gregory Meinkead6d5672019-02-19 08:41:12 -070057 '--cbb_snapshot_revision', 'hash1234',
Gregory Meinke5a25ac72019-01-31 13:20:51 -070058 '--cbb_build_packages', 'pkgA pkgB', 'caroline-postsubmit']
59 options = cbuildbot.ParseCommandLine(parser, argv)
60 expected = ['pkgA', 'pkgB']
Mike Frysinger2d589a12019-08-25 14:15:12 -040061 self.assertEqual(expected, options.cbb_build_packages)
62 self.assertEqual('hash1234', options.cbb_snapshot_revision)