blob: be8a8e23966acd9f1fe05db6ad55dd6337481c3a [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2014 The ChromiumOS Authors
Gaurav Shah298aa372014-01-31 09:27:24 -08002# 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):
Alex Klein1699fab2022-09-08 08:46:06 -060016 """Test for cbuildbot._IsDistributedBuilder."""
Gaurav Shah298aa372014-01-31 09:27:24 -080017
Alex Klein1699fab2022-09-08 08:46:06 -060018 # pylint: disable=protected-access
19 def testIsDistributedBuilder(self):
20 """Tests for _IsDistributedBuilder() under various configurations."""
21 parser = cbuildbot._CreateParser()
22 argv = ["--buildroot", "/foo", "amd64-generic-paladin"]
23 options = cbuildbot.ParseCommandLine(parser, argv)
24 options.buildbot = False
Gaurav Shah298aa372014-01-31 09:27:24 -080025
Alex Klein1699fab2022-09-08 08:46:06 -060026 build_config = dict(manifest_version=False)
27 chrome_rev = None
Gaurav Shah298aa372014-01-31 09:27:24 -080028
Alex Klein1699fab2022-09-08 08:46:06 -060029 def _TestConfig(expected):
30 self.assertEqual(
31 expected,
32 cbuildbot._IsDistributedBuilder(
33 options=options,
34 chrome_rev=chrome_rev,
35 build_config=build_config,
36 ),
37 )
Gaurav Shah298aa372014-01-31 09:27:24 -080038
Alex Klein1699fab2022-09-08 08:46:06 -060039 # Default options.
40 _TestConfig(False)
Gaurav Shah298aa372014-01-31 09:27:24 -080041
Alex Klein1699fab2022-09-08 08:46:06 -060042 build_config["manifest_version"] = True
43 # Not running in buildbot mode even though manifest_version=True.
44 _TestConfig(False)
45 options.buildbot = True
46 _TestConfig(True)
Gaurav Shah298aa372014-01-31 09:27:24 -080047
Alex Klein1699fab2022-09-08 08:46:06 -060048 for chrome_rev in (
49 constants.CHROME_REV_TOT,
50 constants.CHROME_REV_LOCAL,
51 constants.CHROME_REV_SPEC,
52 ):
53 _TestConfig(False)
Gregory Meinke5a25ac72019-01-31 13:20:51 -070054
55
56class PostsubmitBuilderTest(cros_test_lib.TestCase):
Alex Klein1699fab2022-09-08 08:46:06 -060057 """Test for special parameters for ChromeOS Findit Integration."""
Gregory Meinke5a25ac72019-01-31 13:20:51 -070058
Alex Klein1699fab2022-09-08 08:46:06 -060059 def testBuildPackages(self):
60 parser = cbuildbot.CreateParser()
61 argv = [
62 "--buildroot",
63 "/foo",
64 "--buildbot",
65 "--cbb_snapshot_revision",
66 "hash1234",
67 "--cbb_build_packages",
68 "pkgA pkgB",
69 "caroline-postsubmit",
70 ]
71 options = cbuildbot.ParseCommandLine(parser, argv)
72 expected = ["pkgA", "pkgB"]
73 self.assertEqual(expected, options.cbb_build_packages)
74 self.assertEqual("hash1234", options.cbb_snapshot_revision)