Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [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 | """controller_util unittests.""" |
| 6 | |
Greg Edelston | 1f5deb6 | 2023-03-31 14:22:08 -0600 | [diff] [blame^] | 7 | from pathlib import Path |
| 8 | |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 9 | from chromite.api.controller import controller_util |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 10 | from chromite.api.gen.chromite.api import build_api_test_pb2 |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 11 | from chromite.api.gen.chromite.api import sysroot_pb2 |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 12 | from chromite.api.gen.chromiumos import common_pb2 |
Alex Klein | 247d792 | 2023-01-18 15:36:02 -0700 | [diff] [blame] | 13 | from chromite.lib import binpkg |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 14 | from chromite.lib import build_target_lib |
Alex Klein | 7f76832 | 2023-01-18 15:34:01 -0700 | [diff] [blame] | 15 | from chromite.lib import chroot_lib |
Alex Klein | 18a60af | 2020-06-11 12:08:47 -0600 | [diff] [blame] | 16 | from chromite.lib import cros_test_lib |
Alex Klein | 7f76832 | 2023-01-18 15:34:01 -0700 | [diff] [blame] | 17 | from chromite.lib import sysroot_lib |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 18 | from chromite.lib.parser import package_info |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 19 | |
| 20 | |
Michael Mortensen | 9a73c32 | 2019-10-03 17:14:37 -0600 | [diff] [blame] | 21 | class ParseChrootTest(cros_test_lib.MockTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 22 | """ParseChroot tests.""" |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 23 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 24 | def testSuccess(self): |
| 25 | """Test successful handling case.""" |
| 26 | path = "/chroot/path" |
| 27 | cache_dir = "/cache/dir" |
| 28 | chrome_root = "/chrome/root" |
| 29 | use_flags = [{"flag": "useflag1"}, {"flag": "useflag2"}] |
| 30 | features = [{"feature": "feature1"}, {"feature": "feature2"}] |
| 31 | expected_env = { |
| 32 | "USE": "useflag1 useflag2", |
| 33 | "FEATURES": "feature1 feature2", |
| 34 | "CHROME_ORIGIN": "LOCAL_SOURCE", |
| 35 | } |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 36 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 37 | chroot_message = common_pb2.Chroot( |
| 38 | path=path, |
| 39 | cache_dir=cache_dir, |
| 40 | chrome_dir=chrome_root, |
| 41 | env={"use_flags": use_flags, "features": features}, |
| 42 | ) |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 43 | |
Alex Klein | 7f76832 | 2023-01-18 15:34:01 -0700 | [diff] [blame] | 44 | expected = chroot_lib.Chroot( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 45 | path=path, |
| 46 | cache_dir=cache_dir, |
| 47 | chrome_root=chrome_root, |
| 48 | env=expected_env, |
| 49 | ) |
| 50 | result = controller_util.ParseChroot(chroot_message) |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 51 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 52 | self.assertEqual(expected, result) |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 53 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 54 | def testWrongMessage(self): |
| 55 | """Test invalid message type given.""" |
| 56 | with self.assertRaises(AssertionError): |
| 57 | controller_util.ParseChroot(common_pb2.BuildTarget()) |
| 58 | |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 59 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 60 | class ParseSysrootTest(cros_test_lib.MockTestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 61 | """ParseSysroot tests.""" |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 62 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 63 | def testSuccess(self): |
| 64 | """test successful handling case.""" |
| 65 | path = "/build/rare_pokemon" |
| 66 | sysroot_message = sysroot_pb2.Sysroot(path=path) |
Alex Klein | 7f76832 | 2023-01-18 15:34:01 -0700 | [diff] [blame] | 67 | expected = sysroot_lib.Sysroot(path=path) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 68 | result = controller_util.ParseSysroot(sysroot_message) |
| 69 | self.assertEqual(expected, result) |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 70 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 71 | def testWrongMessage(self): |
| 72 | with self.assertRaises(AssertionError): |
| 73 | controller_util.ParseSysroot(common_pb2.BuildTarget()) |
| 74 | |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 75 | |
| 76 | class ParseBuildTargetTest(cros_test_lib.TestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 77 | """ParseBuildTarget tests.""" |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 78 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 79 | def testSuccess(self): |
| 80 | """Test successful handling case.""" |
| 81 | name = "board" |
| 82 | build_target_message = common_pb2.BuildTarget(name=name) |
| 83 | expected = build_target_lib.BuildTarget(name) |
| 84 | result = controller_util.ParseBuildTarget(build_target_message) |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 85 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 86 | self.assertEqual(expected, result) |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 87 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 88 | def testParseProfile(self): |
| 89 | """Test the parsing of a profile.""" |
| 90 | name = "build-target-name" |
| 91 | profile = "profile" |
| 92 | build_target_msg = common_pb2.BuildTarget(name=name) |
| 93 | profile_msg = sysroot_pb2.Profile(name=profile) |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 94 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 95 | expected = build_target_lib.BuildTarget(name, profile=profile) |
| 96 | result = controller_util.ParseBuildTarget( |
| 97 | build_target_msg, profile_message=profile_msg |
| 98 | ) |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 99 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 100 | self.assertEqual(expected, result) |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 101 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 102 | def testWrongMessage(self): |
| 103 | """Test invalid message type given.""" |
| 104 | with self.assertRaises(AssertionError): |
| 105 | controller_util.ParseBuildTarget( |
| 106 | build_api_test_pb2.TestRequestMessage() |
| 107 | ) |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 108 | |
| 109 | |
| 110 | class ParseBuildTargetsTest(cros_test_lib.TestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 111 | """ParseBuildTargets tests.""" |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 112 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 113 | def testSuccess(self): |
| 114 | """Test successful handling case.""" |
| 115 | names = ["foo", "bar", "baz"] |
| 116 | message = build_api_test_pb2.TestRequestMessage() |
| 117 | for name in names: |
| 118 | message.build_targets.add().name = name |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 119 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 120 | result = controller_util.ParseBuildTargets(message.build_targets) |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 121 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 122 | expected = [build_target_lib.BuildTarget(name) for name in names] |
| 123 | self.assertCountEqual(expected, result) |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 124 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 125 | def testWrongMessage(self): |
| 126 | """Wrong message type handling.""" |
| 127 | message = common_pb2.Chroot() |
| 128 | message.env.use_flags.add().flag = "foo" |
| 129 | message.env.use_flags.add().flag = "bar" |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 130 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 131 | with self.assertRaises(AssertionError): |
| 132 | controller_util.ParseBuildTargets(message.env.use_flags) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 133 | |
| 134 | |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 135 | class PackageInfoToCPVTest(cros_test_lib.TestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 136 | """PackageInfoToCPV tests.""" |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 137 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 138 | def testAllFields(self): |
| 139 | """Quick check CPV fields.""" |
| 140 | pi = common_pb2.PackageInfo() |
| 141 | pi.package_name = "pkg" |
| 142 | pi.category = "cat" |
| 143 | pi.version = "2.0.0" |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 144 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 145 | cpv = controller_util.PackageInfoToCPV(pi) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 146 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 147 | self.assertEqual("pkg", cpv.package) |
| 148 | self.assertEqual("cat", cpv.category) |
| 149 | self.assertEqual("2.0.0", cpv.version) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 150 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 151 | def testNoPackageInfo(self): |
| 152 | """Test no package info given.""" |
| 153 | self.assertIsNone(controller_util.PackageInfoToCPV(None)) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 154 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 155 | def testNoPackageName(self): |
| 156 | """Test no package name given.""" |
| 157 | pi = common_pb2.PackageInfo() |
| 158 | pi.category = "cat" |
| 159 | pi.version = "2.0.0" |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 160 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 161 | self.assertIsNone(controller_util.PackageInfoToCPV(pi)) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 162 | |
| 163 | |
| 164 | class PackageInfoToStringTest(cros_test_lib.TestCase): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 165 | """PackageInfoToString tests.""" |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 166 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 167 | def testAllFields(self): |
| 168 | """Test all fields present.""" |
| 169 | pi = common_pb2.PackageInfo() |
| 170 | pi.package_name = "pkg" |
| 171 | pi.category = "cat" |
| 172 | pi.version = "2.0.0" |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 173 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 174 | cpv_str = controller_util.PackageInfoToString(pi) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 175 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 176 | self.assertEqual("cat/pkg-2.0.0", cpv_str) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 177 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 178 | def testNoVersion(self): |
| 179 | """Test no version provided.""" |
| 180 | pi = common_pb2.PackageInfo() |
| 181 | pi.package_name = "pkg" |
| 182 | pi.category = "cat" |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 183 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 184 | cpv_str = controller_util.PackageInfoToString(pi) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 185 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 186 | self.assertEqual("cat/pkg", cpv_str) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 187 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 188 | def testPackageOnly(self): |
| 189 | """Test no version provided.""" |
| 190 | pi = common_pb2.PackageInfo() |
| 191 | pi.package_name = "pkg" |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 192 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 193 | cpv_str = controller_util.PackageInfoToString(pi) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 194 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 195 | self.assertEqual("pkg", cpv_str) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 196 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 197 | def testNoPackageName(self): |
| 198 | """Test no package name given.""" |
| 199 | pi = common_pb2.PackageInfo() |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 200 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 201 | with self.assertRaises(ValueError): |
| 202 | controller_util.PackageInfoToString(pi) |
Alex Klein | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 203 | |
| 204 | |
Alex Klein | 1e68a8e | 2020-10-06 17:25:11 -0600 | [diff] [blame] | 205 | def test_serialize_package_info(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 206 | pkg_info = package_info.parse("foo/bar-1.2.3-r4") |
| 207 | pkg_info_msg = common_pb2.PackageInfo() |
| 208 | controller_util.serialize_package_info(pkg_info, pkg_info_msg) |
| 209 | assert pkg_info_msg.category == "foo" |
| 210 | assert pkg_info_msg.package_name == "bar" |
| 211 | assert pkg_info_msg.version == "1.2.3-r4" |
Alex Klein | 1e68a8e | 2020-10-06 17:25:11 -0600 | [diff] [blame] | 212 | |
| 213 | |
| 214 | def test_deserialize_package_info(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 215 | pkg_info_msg = common_pb2.PackageInfo() |
| 216 | pkg_info_msg.category = "foo" |
| 217 | pkg_info_msg.package_name = "bar" |
| 218 | pkg_info_msg.version = "1.2.3-r4" |
| 219 | pkg_info = controller_util.deserialize_package_info(pkg_info_msg) |
| 220 | assert pkg_info.cpvr == "foo/bar-1.2.3-r4" |
Lizzy Presland | 29e6245 | 2022-01-05 21:58:21 +0000 | [diff] [blame] | 221 | |
| 222 | |
Lizzy Presland | febffa7 | 2022-02-24 23:38:58 +0000 | [diff] [blame] | 223 | def test_retrieve_package_log_paths(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 224 | packages = [ |
| 225 | package_info.parse("foo/bar%d-1.0-r1" % num) for num in range(1, 4) |
| 226 | ] |
| 227 | output_proto = sysroot_pb2.InstallPackagesResponse() |
Alex Klein | 7f76832 | 2023-01-18 15:34:01 -0700 | [diff] [blame] | 228 | target_sysroot = sysroot_lib.Sysroot(path="/path/to/sysroot") |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 229 | controller_util.retrieve_package_log_paths( |
| 230 | packages, output_proto, target_sysroot |
| 231 | ) |
| 232 | assert len(output_proto.failed_package_data) == 3 |
Alex Klein | 247d792 | 2023-01-18 15:36:02 -0700 | [diff] [blame] | 233 | |
| 234 | |
| 235 | def test_package_index_info(): |
| 236 | """Quick check converting to/from protobuf works.""" |
| 237 | sha = "SHA" |
| 238 | number = 5 |
| 239 | build_target_name = "build_target" |
| 240 | profile_name = "profile" |
| 241 | location = "location" |
| 242 | |
| 243 | msg = common_pb2.PackageIndexInfo() |
| 244 | msg.snapshot_sha = sha |
| 245 | msg.snapshot_number = number |
| 246 | msg.build_target.name = build_target_name |
| 247 | msg.profile.name = profile_name |
| 248 | msg.location = location |
| 249 | |
| 250 | obj = binpkg.PackageIndexInfo( |
| 251 | snapshot_sha=sha, |
| 252 | snapshot_number=number, |
| 253 | build_target=build_target_lib.BuildTarget(name=build_target_name), |
| 254 | profile=sysroot_lib.Profile(name=profile_name), |
| 255 | location=location, |
| 256 | ) |
| 257 | |
| 258 | assert obj == controller_util.deserialize_package_index_info(msg) |
Greg Edelston | 1f5deb6 | 2023-03-31 14:22:08 -0600 | [diff] [blame^] | 259 | |
| 260 | |
| 261 | class Pb2PathToPathlibPathTest(cros_test_lib.TestCase): |
| 262 | """Verify functionality for pb2_path_to_pathlib_path().""" |
| 263 | |
| 264 | chroot = common_pb2.Chroot(path="/path/to/chroot") |
| 265 | |
| 266 | @staticmethod |
| 267 | def create_pb2_path(path: str, inside: bool) -> common_pb2.Path: |
| 268 | """Helper function to create a common_pb2.Path.""" |
| 269 | location = ( |
| 270 | common_pb2.Path.Location.INSIDE |
| 271 | if inside |
| 272 | else common_pb2.Path.Location.OUTSIDE |
| 273 | ) |
| 274 | return common_pb2.Path(path=path, location=location) |
| 275 | |
| 276 | def test_relative_inside(self): |
| 277 | """Verify that passing in a relative path inside the chroot fails""" |
| 278 | pb2_path = self.create_pb2_path(path="usr/bin", inside=True) |
| 279 | with self.assertRaises(ValueError): |
| 280 | controller_util.pb2_path_to_pathlib_path( |
| 281 | pb2_path, chroot=self.chroot |
| 282 | ) |
| 283 | |
| 284 | def test_relative_outside(self): |
| 285 | """Verify that passing in a relative path outside the chroot fails""" |
| 286 | pb2_path = self.create_pb2_path(path="usr/bin", inside=False) |
| 287 | with self.assertRaises(ValueError): |
| 288 | controller_util.pb2_path_to_pathlib_path( |
| 289 | pb2_path, chroot=self.chroot |
| 290 | ) |
| 291 | |
| 292 | def test_inside_with_chroot(self): |
| 293 | """Verify that we can convert an inside path with a chroot.""" |
| 294 | pb2_path = self.create_pb2_path(path="/usr/bin", inside=True) |
| 295 | pathlib_path = controller_util.pb2_path_to_pathlib_path( |
| 296 | pb2_path, chroot=self.chroot |
| 297 | ) |
| 298 | self.assertEqual(pathlib_path, Path("/path/to/chroot/usr/bin")) |
| 299 | |
| 300 | def test_outside_with_chroot(self): |
| 301 | """Verify that we can convert an outside path with a chroot.""" |
| 302 | pb2_path = self.create_pb2_path(path="/usr/bin", inside=False) |
| 303 | pathlib_path = controller_util.pb2_path_to_pathlib_path( |
| 304 | pb2_path, chroot=self.chroot |
| 305 | ) |
| 306 | self.assertEqual(pathlib_path, Path("/usr/bin")) |
| 307 | |
| 308 | def test_inside_without_chroot(self): |
| 309 | """Verify that we cannot convert an inside path without a chroot.""" |
| 310 | pb2_path = self.create_pb2_path(path="/usr/bin", inside=True) |
| 311 | with self.assertRaises(ValueError): |
| 312 | controller_util.pb2_path_to_pathlib_path(pb2_path) |
| 313 | |
| 314 | def test_outside_without_chroot(self): |
| 315 | """Verify that we can convert an outside path without a chroot.""" |
| 316 | pb2_path = self.create_pb2_path(path="/usr/bin", inside=False) |
| 317 | pathlib_path = controller_util.pb2_path_to_pathlib_path(pb2_path) |
| 318 | self.assertEqual(pathlib_path, Path("/usr/bin")) |