blob: fdeb26fe278e5f01447199df65390231ffe8e409 [file] [log] [blame]
Mike Frysingere58c0e22017-10-04 15:43:30 -04001# -*- coding: utf-8 -*-
Gaurav Shah298aa372014-01-31 09:27:24 -08002# 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
Aviv Keshetb7519e12016-10-04 00:50:00 -070010from chromite.lib import constants
Gaurav Shah298aa372014-01-31 09:27:24 -080011from chromite.lib import cros_test_lib
12from chromite.scripts import cbuildbot
13
14
Don Garrettb85658c2015-06-30 19:07:22 -070015# pylint: disable=protected-access
16
17
Gaurav Shah298aa372014-01-31 09:27:24 -080018class IsDistributedBuilderTest(cros_test_lib.TestCase):
19 """Test for cbuildbot._IsDistributedBuilder."""
20
Mike Frysinger27e21b72018-07-12 14:20:21 -040021 # pylint: disable=protected-access
Gaurav Shah298aa372014-01-31 09:27:24 -080022 def testIsDistributedBuilder(self):
23 """Tests for _IsDistributedBuilder() under various configurations."""
24 parser = cbuildbot._CreateParser()
Don Garrett211df8c2017-09-06 13:33:02 -070025 argv = ['--buildroot', '/foo', 'amd64-generic-paladin']
Mike Frysinger80bba8a2017-08-18 15:28:36 -040026 options = cbuildbot.ParseCommandLine(parser, argv)
Gaurav Shah298aa372014-01-31 09:27:24 -080027 options.buildbot = False
Gaurav Shah298aa372014-01-31 09:27:24 -080028
29 build_config = dict(pre_cq=False,
30 manifest_version=False)
31 chrome_rev = None
32
33 def _TestConfig(expected):
Mike Frysinger2d589a12019-08-25 14:15:12 -040034 self.assertEqual(expected,
35 cbuildbot._IsDistributedBuilder(
36 options=options,
37 chrome_rev=chrome_rev,
38 build_config=build_config))
Gaurav Shah298aa372014-01-31 09:27:24 -080039
40 # Default options.
41 _TestConfig(False)
42
Gaurav Shah298aa372014-01-31 09:27:24 -080043 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 Meinke5a25ac72019-01-31 13:20:51 -070057
58
59class 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 Meinkead6d5672019-02-19 08:41:12 -070065 '--cbb_snapshot_revision', 'hash1234',
Gregory Meinke5a25ac72019-01-31 13:20:51 -070066 '--cbb_build_packages', 'pkgA pkgB', 'caroline-postsubmit']
67 options = cbuildbot.ParseCommandLine(parser, argv)
68 expected = ['pkgA', 'pkgB']
Mike Frysinger2d589a12019-08-25 14:15:12 -040069 self.assertEqual(expected, options.cbb_build_packages)
70 self.assertEqual('hash1234', options.cbb_snapshot_revision)