blob: 6937c1d2de9975703afd6f5b5589d84f96bbac5d [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2022 The ChromiumOS Authors
Ram Chandrasekar75c5d482022-08-01 22:17:47 +00002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Unittests for strip_package.py"""
Mike Frysinger93afe3e2023-09-05 14:18:52 -04006
Ram Chandrasekar75c5d482022-08-01 22:17:47 +00007import os
8
9from chromite.lib import build_target_lib
10from chromite.lib import cros_test_lib
11from chromite.lib import install_mask
12from chromite.scripts import strip_package
13
14
15class StripPackageTest(cros_test_lib.MockTestCase):
Alex Klein1699fab2022-09-08 08:46:06 -060016 """Tests for strip_package."""
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000017
Alex Klein1699fab2022-09-08 08:46:06 -060018 def setUp(self):
19 self.sysroot_path = "/build/testboard"
20 self.builder_mock = self.PatchObject(
21 strip_package.builder, "UpdateGmergeBinhost"
22 )
23 self.PatchObject(
24 build_target_lib,
25 "get_default_sysroot_path",
26 return_value=self.sysroot_path,
27 )
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000028
Alex Klein1699fab2022-09-08 08:46:06 -060029 def testDefaultSysroot(self):
30 """Test the base case."""
31 strip_package.main(["--board=testboard", "foo"])
32 self.builder_mock.assert_called_with(self.sysroot_path, ["foo"], False)
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000033
Alex Klein1699fab2022-09-08 08:46:06 -060034 def testMultiplePkg(self):
35 """Test multiple package input."""
36 strip_package.main(["--board=testboard", "foo", "foo1"])
37 self.builder_mock.assert_called_with(
38 self.sysroot_path, ["foo", "foo1"], False
39 )
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000040
Alex Klein1699fab2022-09-08 08:46:06 -060041 def testCustomSysroot(self):
42 """Test user given custom sysroot path."""
43 strip_package.main(["--sysroot=/build/sysroot", "foo"])
44 self.builder_mock.assert_called_with("/build/sysroot", ["foo"], False)
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000045
Alex Klein1699fab2022-09-08 08:46:06 -060046 def testInstallMask(self):
47 """Test install mask environment variable."""
48 strip_package.main(["--board=testboard", "foo"])
49 self.assertEqual(
50 os.environ.get("DEFAULT_INSTALL_MASK"),
51 "\n".join(install_mask.DEFAULT),
52 )
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000053
Alex Klein1699fab2022-09-08 08:46:06 -060054 def testDeepOption(self):
55 """Test Deep option."""
56 strip_package.main(["--board=testboard", "--deep", "foo"])
57 self.builder_mock.assert_called_with(self.sysroot_path, ["foo"], True)