Mike Frysinger | e58c0e2 | 2017-10-04 15:43:30 -0400 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 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 Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 8 | from __future__ import print_function |
| 9 | |
Aviv Keshet | b7519e1 | 2016-10-04 00:50:00 -0700 | [diff] [blame] | 10 | from chromite.lib import constants |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 11 | from chromite.lib import cros_test_lib |
| 12 | from chromite.scripts import cbuildbot |
| 13 | |
| 14 | |
Don Garrett | b85658c | 2015-06-30 19:07:22 -0700 | [diff] [blame] | 15 | # pylint: disable=protected-access |
| 16 | |
| 17 | |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 18 | class IsDistributedBuilderTest(cros_test_lib.TestCase): |
| 19 | """Test for cbuildbot._IsDistributedBuilder.""" |
| 20 | |
Mike Frysinger | 27e21b7 | 2018-07-12 14:20:21 -0400 | [diff] [blame] | 21 | # pylint: disable=protected-access |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 22 | def testIsDistributedBuilder(self): |
| 23 | """Tests for _IsDistributedBuilder() under various configurations.""" |
| 24 | parser = cbuildbot._CreateParser() |
Don Garrett | 211df8c | 2017-09-06 13:33:02 -0700 | [diff] [blame] | 25 | argv = ['--buildroot', '/foo', 'amd64-generic-paladin'] |
Mike Frysinger | 80bba8a | 2017-08-18 15:28:36 -0400 | [diff] [blame] | 26 | options = cbuildbot.ParseCommandLine(parser, argv) |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 27 | options.buildbot = False |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 28 | |
| 29 | build_config = dict(pre_cq=False, |
| 30 | manifest_version=False) |
| 31 | chrome_rev = None |
| 32 | |
| 33 | def _TestConfig(expected): |
Mike Frysinger | 2d589a1 | 2019-08-25 14:15:12 -0400 | [diff] [blame] | 34 | self.assertEqual(expected, |
| 35 | cbuildbot._IsDistributedBuilder( |
| 36 | options=options, |
| 37 | chrome_rev=chrome_rev, |
| 38 | build_config=build_config)) |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 39 | |
| 40 | # Default options. |
| 41 | _TestConfig(False) |
| 42 | |
Gaurav Shah | 298aa37 | 2014-01-31 09:27:24 -0800 | [diff] [blame] | 43 | build_config['pre_cq'] = True |
| 44 | _TestConfig(True) |
| 45 | |
| 46 | build_config['pre_cq'] = False |
| 47 | build_config['manifest_version'] = True |
| 48 | # Not running in buildbot mode even though manifest_version=True. |
| 49 | _TestConfig(False) |
| 50 | options.buildbot = True |
| 51 | _TestConfig(True) |
| 52 | |
| 53 | for chrome_rev in (constants.CHROME_REV_TOT, |
| 54 | constants.CHROME_REV_LOCAL, |
| 55 | constants.CHROME_REV_SPEC): |
| 56 | _TestConfig(False) |
Gregory Meinke | 5a25ac7 | 2019-01-31 13:20:51 -0700 | [diff] [blame] | 57 | |
| 58 | |
| 59 | class PostsubmitBuilderTest(cros_test_lib.TestCase): |
| 60 | """Test for special parameters for ChromeOS Findit Integration.""" |
| 61 | |
| 62 | def testBuildPackages(self): |
| 63 | parser = cbuildbot.CreateParser() |
| 64 | argv = ['--buildroot', '/foo', '--buildbot', |
Gregory Meinke | ad6d567 | 2019-02-19 08:41:12 -0700 | [diff] [blame] | 65 | '--cbb_snapshot_revision', 'hash1234', |
Gregory Meinke | 5a25ac7 | 2019-01-31 13:20:51 -0700 | [diff] [blame] | 66 | '--cbb_build_packages', 'pkgA pkgB', 'caroline-postsubmit'] |
| 67 | options = cbuildbot.ParseCommandLine(parser, argv) |
| 68 | expected = ['pkgA', 'pkgB'] |
Mike Frysinger | 2d589a1 | 2019-08-25 14:15:12 -0400 | [diff] [blame] | 69 | self.assertEqual(expected, options.cbb_build_packages) |
| 70 | self.assertEqual('hash1234', options.cbb_snapshot_revision) |