blob: 830106b0e6f43764c0ae37fc563e3d8a82d0673c [file] [log] [blame]
Ram Chandrasekar75c5d482022-08-01 22:17:47 +00001# Copyright 2022 The ChromiumOS Authors.
2# 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"""
6import os
7
8from chromite.lib import build_target_lib
9from chromite.lib import cros_test_lib
10from chromite.lib import install_mask
11from chromite.scripts import strip_package
12
13
14class StripPackageTest(cros_test_lib.MockTestCase):
Alex Klein1699fab2022-09-08 08:46:06 -060015 """Tests for strip_package."""
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000016
Alex Klein1699fab2022-09-08 08:46:06 -060017 def setUp(self):
18 self.sysroot_path = "/build/testboard"
19 self.builder_mock = self.PatchObject(
20 strip_package.builder, "UpdateGmergeBinhost"
21 )
22 self.PatchObject(
23 build_target_lib,
24 "get_default_sysroot_path",
25 return_value=self.sysroot_path,
26 )
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000027
Alex Klein1699fab2022-09-08 08:46:06 -060028 def testDefaultSysroot(self):
29 """Test the base case."""
30 strip_package.main(["--board=testboard", "foo"])
31 self.builder_mock.assert_called_with(self.sysroot_path, ["foo"], False)
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000032
Alex Klein1699fab2022-09-08 08:46:06 -060033 def testMultiplePkg(self):
34 """Test multiple package input."""
35 strip_package.main(["--board=testboard", "foo", "foo1"])
36 self.builder_mock.assert_called_with(
37 self.sysroot_path, ["foo", "foo1"], False
38 )
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000039
Alex Klein1699fab2022-09-08 08:46:06 -060040 def testCustomSysroot(self):
41 """Test user given custom sysroot path."""
42 strip_package.main(["--sysroot=/build/sysroot", "foo"])
43 self.builder_mock.assert_called_with("/build/sysroot", ["foo"], False)
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000044
Alex Klein1699fab2022-09-08 08:46:06 -060045 def testInstallMask(self):
46 """Test install mask environment variable."""
47 strip_package.main(["--board=testboard", "foo"])
48 self.assertEqual(
49 os.environ.get("DEFAULT_INSTALL_MASK"),
50 "\n".join(install_mask.DEFAULT),
51 )
Ram Chandrasekar75c5d482022-08-01 22:17:47 +000052
Alex Klein1699fab2022-09-08 08:46:06 -060053 def testDeepOption(self):
54 """Test Deep option."""
55 strip_package.main(["--board=testboard", "--deep", "foo"])
56 self.builder_mock.assert_called_with(self.sysroot_path, ["foo"], True)