Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2014 The ChromiumOS Authors |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 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 Keshet | b7519e1 | 2016-10-04 00:50:00 -0700 | [diff] [blame] | 7 | from chromite.lib import constants |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 8 | from chromite.lib import cros_test_lib |
| 9 | from chromite.scripts import cbuildbot |
| 10 | |
| 11 | |
Don Garrett | b85658c | 2015-06-30 19:07:22 -0700 | [diff] [blame] | 12 | # pylint: disable=protected-access |
| 13 | |
| 14 | |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 15 | class IsDistributedBuilderTest(cros_test_lib.TestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 16 | """Test for cbuildbot._IsDistributedBuilder.""" |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 17 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 18 | # 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 Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 25 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 26 | build_config = dict(manifest_version=False) |
| 27 | chrome_rev = None |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 28 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 29 | 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 Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 38 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 39 | # Default options. |
| 40 | _TestConfig(False) |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 41 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 42 | 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 Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 47 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 48 | for chrome_rev in ( |
| 49 | constants.CHROME_REV_TOT, |
| 50 | constants.CHROME_REV_LOCAL, |
| 51 | constants.CHROME_REV_SPEC, |
| 52 | ): |
| 53 | _TestConfig(False) |
Gregory Meinke | 5a25ac7 | 2019-01-31 13:20:51 -0700 | [diff] [blame] | 54 | |
| 55 | |
| 56 | class PostsubmitBuilderTest(cros_test_lib.TestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 57 | """Test for special parameters for ChromeOS Findit Integration.""" |
Gregory Meinke | 5a25ac7 | 2019-01-31 13:20:51 -0700 | [diff] [blame] | 58 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 59 | 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) |