Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -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 | """Unittests for Binhost operations.""" |
| 6 | |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 7 | import os |
Mike Frysinger | 166fea0 | 2021-02-12 05:30:33 -0500 | [diff] [blame] | 8 | from unittest import mock |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame] | 9 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 10 | from chromite.api import api_config |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 11 | from chromite.api.controller import binhost |
| 12 | from chromite.api.gen.chromite.api import binhost_pb2 |
Greg Edelston | 724c13d | 2023-04-07 16:19:24 -0600 | [diff] [blame] | 13 | from chromite.api.gen.chromiumos import common_pb2 |
| 14 | from chromite.lib import binpkg |
Cindy Lin | d4c122a | 2023-04-13 19:09:31 +0000 | [diff] [blame^] | 15 | from chromite.lib import constants |
LaMont Jones | c64ae21 | 2019-04-15 15:41:28 -0600 | [diff] [blame] | 16 | from chromite.lib import cros_build_lib |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 17 | from chromite.lib import cros_test_lib |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 18 | from chromite.lib import osutils |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 19 | from chromite.service import binhost as binhost_service |
| 20 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 21 | |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 22 | class GetBinhostsTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 23 | """Unittests for GetBinhosts.""" |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 24 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 25 | def setUp(self): |
| 26 | self.response = binhost_pb2.BinhostGetResponse() |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 27 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 28 | def testValidateOnly(self): |
| 29 | """Check that a validate only call does not execute any logic.""" |
| 30 | patch = self.PatchObject(binhost_service, "GetBinhosts") |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 31 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 32 | request = binhost_pb2.BinhostGetRequest() |
| 33 | request.build_target.name = "target" |
| 34 | binhost.GetBinhosts(request, self.response, self.validate_only_config) |
| 35 | patch.assert_not_called() |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 36 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 37 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 38 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 39 | patch = self.PatchObject(binhost_service, "GetBinhosts") |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 40 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 41 | input_proto = binhost_pb2.BinhostGetRequest() |
| 42 | input_proto.build_target.name = "target" |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 43 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 44 | binhost.GetBinhosts(input_proto, self.response, self.mock_call_config) |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 45 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 46 | self.assertEqual(len(self.response.binhosts), 1) |
| 47 | self.assertEqual(self.response.binhosts[0].package_index, "Packages") |
| 48 | patch.assert_not_called() |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 49 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 50 | def testGetBinhosts(self): |
| 51 | """GetBinhosts calls service with correct args.""" |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 52 | # pylint: disable=line-too-long |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 53 | binhost_list = [ |
| 54 | "gs://cr-prebuilt/board/amd64-generic/paladin-R66-17.0.0-rc2/packages/", |
| 55 | "gs://cr-prebuilt/board/eve/paladin-R66-17.0.0-rc2/packages/", |
| 56 | ] |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 57 | # pylint: enable=line-too-long |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 58 | get_binhost = self.PatchObject( |
| 59 | binhost_service, "GetBinhosts", return_value=binhost_list |
| 60 | ) |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 61 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 62 | input_proto = binhost_pb2.BinhostGetRequest() |
| 63 | input_proto.build_target.name = "target" |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 64 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 65 | binhost.GetBinhosts(input_proto, self.response, self.api_config) |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 66 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 67 | self.assertEqual(len(self.response.binhosts), 2) |
| 68 | self.assertEqual(self.response.binhosts[0].package_index, "Packages") |
| 69 | get_binhost.assert_called_once_with(mock.ANY) |
Michael Mortensen | a0af77b | 2019-11-13 11:15:15 -0700 | [diff] [blame] | 70 | |
| 71 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 72 | class GetPrivatePrebuiltAclArgsTest( |
| 73 | cros_test_lib.MockTestCase, api_config.ApiConfigMixin |
| 74 | ): |
| 75 | """Unittests for GetPrivatePrebuiltAclArgs.""" |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 76 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 77 | def setUp(self): |
| 78 | self.response = binhost_pb2.AclArgsResponse() |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 79 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 80 | def testValidateOnly(self): |
| 81 | """Check that a validate only call does not execute any logic.""" |
| 82 | patch = self.PatchObject(binhost_service, "GetPrebuiltAclArgs") |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 83 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 84 | request = binhost_pb2.AclArgsRequest() |
| 85 | request.build_target.name = "target" |
| 86 | binhost.GetPrivatePrebuiltAclArgs( |
| 87 | request, self.response, self.validate_only_config |
| 88 | ) |
| 89 | patch.assert_not_called() |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 90 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 91 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 92 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 93 | patch = self.PatchObject(binhost_service, "GetPrebuiltAclArgs") |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 94 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 95 | input_proto = binhost_pb2.AclArgsRequest() |
| 96 | input_proto.build_target.name = "target" |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 97 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 98 | binhost.GetPrivatePrebuiltAclArgs( |
| 99 | input_proto, self.response, self.mock_call_config |
| 100 | ) |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 101 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 102 | self.assertEqual(len(self.response.args), 1) |
| 103 | self.assertEqual(self.response.args[0].arg, "-g") |
| 104 | self.assertEqual(self.response.args[0].value, "group1:READ") |
| 105 | patch.assert_not_called() |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 106 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 107 | def testGetPrivatePrebuiltAclArgs(self): |
| 108 | """GetPrivatePrebuildAclsArgs calls service with correct args.""" |
| 109 | argvalue_list = [["-g", "group1:READ"]] |
| 110 | get_binhost = self.PatchObject( |
| 111 | binhost_service, "GetPrebuiltAclArgs", return_value=argvalue_list |
| 112 | ) |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 113 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 114 | input_proto = binhost_pb2.AclArgsRequest() |
| 115 | input_proto.build_target.name = "target" |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 116 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 117 | binhost.GetPrivatePrebuiltAclArgs( |
| 118 | input_proto, self.response, self.api_config |
| 119 | ) |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 120 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 121 | self.assertEqual(len(self.response.args), 1) |
| 122 | self.assertEqual(self.response.args[0].arg, "-g") |
| 123 | self.assertEqual(self.response.args[0].value, "group1:READ") |
| 124 | get_binhost.assert_called_once_with(mock.ANY) |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 125 | |
| 126 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 127 | class PrepareBinhostUploadsTest( |
| 128 | cros_test_lib.MockTestCase, api_config.ApiConfigMixin |
| 129 | ): |
| 130 | """Unittests for PrepareBinhostUploads.""" |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 131 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 132 | def setUp(self): |
| 133 | self.PatchObject( |
| 134 | binhost_service, |
| 135 | "GetPrebuiltsRoot", |
| 136 | return_value="/build/target/packages", |
| 137 | ) |
| 138 | self.PatchObject( |
| 139 | binhost_service, |
| 140 | "GetPrebuiltsFiles", |
| 141 | return_value=["foo.tbz2", "bar.tbz2"], |
| 142 | ) |
| 143 | self.PatchObject( |
| 144 | binhost_service, |
| 145 | "UpdatePackageIndex", |
| 146 | return_value="/build/target/packages/Packages", |
| 147 | ) |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 148 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 149 | self.response = binhost_pb2.PrepareBinhostUploadsResponse() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 150 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 151 | def testValidateOnly(self): |
| 152 | """Check that a validate only call does not execute any logic.""" |
| 153 | patch = self.PatchObject(binhost_service, "GetPrebuiltsRoot") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 154 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 155 | request = binhost_pb2.PrepareBinhostUploadsRequest() |
| 156 | request.build_target.name = "target" |
| 157 | request.uri = "gs://chromeos-prebuilt/target" |
| 158 | rc = binhost.PrepareBinhostUploads( |
| 159 | request, self.response, self.validate_only_config |
| 160 | ) |
| 161 | patch.assert_not_called() |
| 162 | self.assertEqual(rc, 0) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 163 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 164 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 165 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 166 | patch = self.PatchObject(binhost_service, "GetPrebuiltsRoot") |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 167 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 168 | request = binhost_pb2.PrepareBinhostUploadsRequest() |
| 169 | request.build_target.name = "target" |
| 170 | request.uri = "gs://chromeos-prebuilt/target" |
| 171 | rc = binhost.PrepareBinhostUploads( |
| 172 | request, self.response, self.mock_call_config |
| 173 | ) |
| 174 | self.assertEqual(self.response.uploads_dir, "/upload/directory") |
| 175 | self.assertEqual(self.response.upload_targets[0].path, "upload_target") |
| 176 | patch.assert_not_called() |
| 177 | self.assertEqual(rc, 0) |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 178 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 179 | def testPrepareBinhostUploads(self): |
| 180 | """PrepareBinhostUploads returns Packages and tar files.""" |
| 181 | input_proto = binhost_pb2.PrepareBinhostUploadsRequest() |
| 182 | input_proto.build_target.name = "target" |
| 183 | input_proto.uri = "gs://chromeos-prebuilt/target" |
| 184 | binhost.PrepareBinhostUploads( |
| 185 | input_proto, self.response, self.api_config |
| 186 | ) |
| 187 | self.assertEqual(self.response.uploads_dir, "/build/target/packages") |
| 188 | self.assertCountEqual( |
| 189 | [ut.path for ut in self.response.upload_targets], |
| 190 | ["Packages", "foo.tbz2", "bar.tbz2"], |
| 191 | ) |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 192 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 193 | def testPrepareBinhostUploadsNonGsUri(self): |
| 194 | """PrepareBinhostUploads dies when URI does not point to GS.""" |
| 195 | input_proto = binhost_pb2.PrepareBinhostUploadsRequest() |
| 196 | input_proto.build_target.name = "target" |
| 197 | input_proto.uri = "https://foo.bar" |
| 198 | with self.assertRaises(ValueError): |
| 199 | binhost.PrepareBinhostUploads( |
| 200 | input_proto, self.response, self.api_config |
| 201 | ) |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 202 | |
| 203 | |
Greg Edelston | 724c13d | 2023-04-07 16:19:24 -0600 | [diff] [blame] | 204 | class UpdatePackageIndexTest( |
| 205 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 206 | ): |
| 207 | """Unit tests for BinhostService/UpdatePackageIndex.""" |
| 208 | |
| 209 | def setUp(self): |
| 210 | self._original_pkg_index = binpkg.PackageIndex() |
| 211 | self._original_pkg_index.header["A"] = "B" |
| 212 | self._original_pkg_index.packages = [ |
| 213 | { |
| 214 | "CPV": "foo/bar", |
| 215 | "KEY": "value", |
| 216 | }, |
| 217 | { |
| 218 | "CPV": "cat/pkg", |
| 219 | "KEY": "also_value", |
| 220 | }, |
| 221 | ] |
| 222 | self._pkg_index_fp = os.path.join( |
| 223 | self.tempdir, |
| 224 | "path/to/packages/Packages", |
| 225 | ) |
| 226 | |
| 227 | def _write_original_package_index(self): |
| 228 | """Write the package index to the tempdir. |
| 229 | |
| 230 | Note that if an input_proto specifies location=INSIDE, then they will |
| 231 | not be able to find the written file, since the tempdir isn't actually |
| 232 | inside a chroot. |
| 233 | """ |
| 234 | osutils.Touch(self._pkg_index_fp, makedirs=True) |
| 235 | self._original_pkg_index.WriteFile(self._pkg_index_fp) |
| 236 | |
| 237 | def testValidateOnly(self): |
| 238 | """Check that a validate only call does not execute any logic.""" |
| 239 | self._write_original_package_index() |
| 240 | patch = self.PatchObject(binpkg.PackageIndex, "ReadFilePath") |
| 241 | request = binhost_pb2.UpdatePackageIndexRequest( |
| 242 | package_index_file=common_pb2.Path( |
| 243 | path=self._pkg_index_fp, |
| 244 | location=common_pb2.Path.Location.OUTSIDE, |
| 245 | ), |
| 246 | set_upload_location=True, |
| 247 | ) |
| 248 | response = binhost_pb2.UpdatePackageIndexResponse() |
| 249 | binhost.UpdatePackageIndex(request, response, self.validate_only_config) |
| 250 | patch.assert_not_called() |
| 251 | |
| 252 | def testMustProvideSomeCommand(self): |
| 253 | """Test that an error is raised if no update types are specified.""" |
| 254 | self._write_original_package_index() |
| 255 | request = binhost_pb2.UpdatePackageIndexRequest( |
| 256 | package_index_file=common_pb2.Path( |
| 257 | path=self._pkg_index_fp, |
| 258 | location=common_pb2.Path.OUTSIDE, |
| 259 | ), |
| 260 | uri="gs://chromeos-prebuilt/board/amd64-host/packages", |
| 261 | ) |
| 262 | response = binhost_pb2.UpdatePackageIndexResponse() |
| 263 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 264 | binhost.UpdatePackageIndex(request, response, self.api_config) |
| 265 | |
| 266 | def testSetUploadLocation(self): |
| 267 | """Test setting the package upload location in the index file. |
| 268 | |
| 269 | This test includes correctly parsing the input uri. |
| 270 | """ |
| 271 | # Arrange |
| 272 | self._write_original_package_index() |
| 273 | |
| 274 | # Act |
| 275 | request = binhost_pb2.UpdatePackageIndexRequest( |
| 276 | package_index_file=common_pb2.Path( |
| 277 | path=self._pkg_index_fp, |
| 278 | location=common_pb2.Path.Location.OUTSIDE, |
| 279 | ), |
| 280 | set_upload_location=True, |
| 281 | uri="gs://chromeos-prebuilt/board/amd64-host/packages/", |
| 282 | ) |
| 283 | response = binhost_pb2.UpdatePackageIndexResponse() |
| 284 | binhost.UpdatePackageIndex(request, response, self.api_config) |
| 285 | |
| 286 | # Assert |
| 287 | new_pkg_index = binpkg.PackageIndex() |
| 288 | new_pkg_index.ReadFilePath(self._pkg_index_fp) |
| 289 | self.assertEqual(new_pkg_index.header["URI"], "gs://chromeos-prebuilt") |
| 290 | self.assertDictEqual( |
| 291 | new_pkg_index.packages[0], |
| 292 | { |
| 293 | "CPV": "cat/pkg", |
| 294 | "KEY": "also_value", |
| 295 | "PATH": "board/amd64-host/packages/cat/pkg.tbz2", |
| 296 | }, |
| 297 | ) |
| 298 | self.assertDictEqual( |
| 299 | new_pkg_index.packages[1], |
| 300 | { |
| 301 | "CPV": "foo/bar", |
| 302 | "KEY": "value", |
| 303 | "PATH": "board/amd64-host/packages/foo/bar.tbz2", |
| 304 | }, |
| 305 | ) |
| 306 | |
| 307 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 308 | class SetBinhostTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 309 | """Unittests for SetBinhost.""" |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 310 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 311 | def setUp(self): |
| 312 | self.response = binhost_pb2.SetBinhostResponse() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 313 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 314 | def testValidateOnly(self): |
| 315 | """Check that a validate only call does not execute any logic.""" |
| 316 | patch = self.PatchObject(binhost_service, "SetBinhost") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 317 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 318 | request = binhost_pb2.SetBinhostRequest() |
| 319 | request.build_target.name = "target" |
| 320 | request.key = binhost_pb2.POSTSUBMIT_BINHOST |
| 321 | request.uri = "gs://chromeos-prebuilt/target" |
| 322 | binhost.SetBinhost(request, self.response, self.validate_only_config) |
| 323 | patch.assert_not_called() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 324 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 325 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 326 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 327 | patch = self.PatchObject(binhost_service, "SetBinhost") |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 328 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 329 | request = binhost_pb2.SetBinhostRequest() |
| 330 | request.build_target.name = "target" |
| 331 | request.key = binhost_pb2.POSTSUBMIT_BINHOST |
| 332 | request.uri = "gs://chromeos-prebuilt/target" |
Arif Kasim | 6242cdd | 2022-10-19 17:51:00 +0000 | [diff] [blame] | 333 | request.max_uris = 4 |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 334 | binhost.SetBinhost(request, self.response, self.mock_call_config) |
| 335 | patch.assert_not_called() |
| 336 | self.assertEqual(self.response.output_file, "/path/to/BINHOST.conf") |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 337 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 338 | def testSetBinhost(self): |
| 339 | """SetBinhost calls service with correct args.""" |
| 340 | set_binhost = self.PatchObject( |
| 341 | binhost_service, "SetBinhost", return_value="/path/to/BINHOST.conf" |
| 342 | ) |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 343 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 344 | input_proto = binhost_pb2.SetBinhostRequest() |
| 345 | input_proto.build_target.name = "target" |
| 346 | input_proto.private = True |
| 347 | input_proto.key = binhost_pb2.POSTSUBMIT_BINHOST |
| 348 | input_proto.uri = "gs://chromeos-prebuilt/target" |
Arif Kasim | 6242cdd | 2022-10-19 17:51:00 +0000 | [diff] [blame] | 349 | input_proto.max_uris = 4 |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 350 | binhost.SetBinhost(input_proto, self.response, self.api_config) |
Evan Hernandez | d437b4e | 2019-03-25 13:48:30 -0600 | [diff] [blame] | 351 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 352 | self.assertEqual(self.response.output_file, "/path/to/BINHOST.conf") |
| 353 | set_binhost.assert_called_once_with( |
| 354 | "target", |
| 355 | "POSTSUBMIT_BINHOST", |
| 356 | "gs://chromeos-prebuilt/target", |
| 357 | private=True, |
Arif Kasim | 6242cdd | 2022-10-19 17:51:00 +0000 | [diff] [blame] | 358 | max_uris=4, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 359 | ) |
LaMont Jones | c64ae21 | 2019-04-15 15:41:28 -0600 | [diff] [blame] | 360 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 361 | |
Arif Kasim | a046726 | 2022-11-11 17:08:14 +0000 | [diff] [blame] | 362 | class GetBinhostConfPathTest( |
| 363 | cros_test_lib.MockTestCase, api_config.ApiConfigMixin |
| 364 | ): |
| 365 | """Unittests for GetBinhostConfPath.""" |
| 366 | |
| 367 | def setUp(self): |
| 368 | self.response = binhost_pb2.GetBinhostConfPathResponse() |
| 369 | |
| 370 | def testValidateOnly(self): |
| 371 | """Check that a validate only call does not execute any logic.""" |
| 372 | patch = self.PatchObject(binhost_service, "GetBinhostConfPath") |
| 373 | |
| 374 | request = binhost_pb2.GetBinhostConfPathRequest() |
| 375 | request.build_target.name = "target" |
| 376 | request.key = binhost_pb2.POSTSUBMIT_BINHOST |
| 377 | binhost.GetBinhostConfPath( |
| 378 | request, self.response, self.validate_only_config |
| 379 | ) |
| 380 | patch.assert_not_called() |
| 381 | |
| 382 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 383 | """Test a mock call does not execute logic, returns mocked value.""" |
Arif Kasim | a046726 | 2022-11-11 17:08:14 +0000 | [diff] [blame] | 384 | patch = self.PatchObject(binhost_service, "GetBinhostConfPath") |
| 385 | |
| 386 | request = binhost_pb2.GetBinhostConfPathRequest() |
| 387 | request.build_target.name = "target" |
| 388 | request.key = binhost_pb2.POSTSUBMIT_BINHOST |
| 389 | binhost.GetBinhostConfPath( |
| 390 | request, self.response, self.mock_call_config |
| 391 | ) |
| 392 | patch.assert_not_called() |
| 393 | self.assertEqual(self.response.conf_path, "/path/to/BINHOST.conf") |
| 394 | |
| 395 | def testGetBinhostConfPath(self): |
| 396 | """GetBinhostConfPath calls service with correct args.""" |
| 397 | get_binhost_conf_path = self.PatchObject( |
| 398 | binhost_service, |
| 399 | "GetBinhostConfPath", |
| 400 | return_value="/path/to/BINHOST.conf", |
| 401 | ) |
| 402 | input_proto = binhost_pb2.GetBinhostConfPathRequest() |
| 403 | input_proto.build_target.name = "target" |
| 404 | input_proto.private = True |
| 405 | input_proto.key = binhost_pb2.POSTSUBMIT_BINHOST |
| 406 | binhost.GetBinhostConfPath(input_proto, self.response, self.api_config) |
| 407 | |
| 408 | self.assertEqual(self.response.conf_path, "/path/to/BINHOST.conf") |
| 409 | get_binhost_conf_path.assert_called_once_with( |
| 410 | "target", |
| 411 | "POSTSUBMIT_BINHOST", |
| 412 | True, |
| 413 | ) |
| 414 | |
| 415 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 416 | class RegenBuildCacheTest( |
| 417 | cros_test_lib.MockTestCase, api_config.ApiConfigMixin |
| 418 | ): |
| 419 | """Unittests for RegenBuildCache.""" |
LaMont Jones | c64ae21 | 2019-04-15 15:41:28 -0600 | [diff] [blame] | 420 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 421 | def setUp(self): |
| 422 | self.response = binhost_pb2.RegenBuildCacheResponse() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 423 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 424 | def testValidateOnly(self): |
| 425 | """Check that a validate only call does not execute any logic.""" |
| 426 | patch = self.PatchObject(binhost_service, "RegenBuildCache") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 427 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 428 | request = binhost_pb2.RegenBuildCacheRequest() |
| 429 | request.overlay_type = binhost_pb2.OVERLAYTYPE_BOTH |
| 430 | binhost.RegenBuildCache( |
| 431 | request, self.response, self.validate_only_config |
| 432 | ) |
| 433 | patch.assert_not_called() |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 434 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 435 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 436 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 437 | patch = self.PatchObject(binhost_service, "RegenBuildCache") |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 438 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 439 | request = binhost_pb2.RegenBuildCacheRequest() |
| 440 | request.overlay_type = binhost_pb2.OVERLAYTYPE_BOTH |
| 441 | binhost.RegenBuildCache(request, self.response, self.mock_call_config) |
| 442 | patch.assert_not_called() |
| 443 | self.assertEqual(len(self.response.modified_overlays), 1) |
| 444 | self.assertEqual( |
| 445 | self.response.modified_overlays[0].path, "/path/to/BuildCache" |
| 446 | ) |
| 447 | |
| 448 | def testRegenBuildCache(self): |
| 449 | """RegenBuildCache calls service with the correct args.""" |
| 450 | regen_cache = self.PatchObject(binhost_service, "RegenBuildCache") |
| 451 | |
| 452 | input_proto = binhost_pb2.RegenBuildCacheRequest() |
| 453 | input_proto.overlay_type = binhost_pb2.OVERLAYTYPE_BOTH |
| 454 | |
| 455 | binhost.RegenBuildCache(input_proto, self.response, self.api_config) |
| 456 | regen_cache.assert_called_once_with(mock.ANY, "both") |
| 457 | |
| 458 | def testRequiresOverlayType(self): |
| 459 | """RegenBuildCache dies if overlay_type not specified.""" |
| 460 | regen_cache = self.PatchObject(binhost_service, "RegenBuildCache") |
| 461 | |
| 462 | input_proto = binhost_pb2.RegenBuildCacheRequest() |
| 463 | input_proto.overlay_type = binhost_pb2.OVERLAYTYPE_UNSPECIFIED |
| 464 | |
| 465 | with self.assertRaises(cros_build_lib.DieSystemExit): |
| 466 | binhost.RegenBuildCache(input_proto, self.response, self.api_config) |
| 467 | regen_cache.assert_not_called() |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 468 | |
| 469 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 470 | class PrepareDevInstallerBinhostUploadsTest( |
| 471 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 472 | ): |
| 473 | """Tests for the UploadDevInstallerPrebuilts stage.""" |
LaMont Jones | c64ae21 | 2019-04-15 15:41:28 -0600 | [diff] [blame] | 474 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 475 | def setUp(self): |
| 476 | self.PatchObject(cros_build_lib, "IsInsideChroot", return_value=False) |
| 477 | # target packages dir |
| 478 | self.chroot_path = os.path.join(self.tempdir, "chroot") |
| 479 | self.sysroot_path = "/build/target" |
| 480 | self.chroot_path = os.path.join(self.tempdir, "chroot") |
| 481 | full_sysroot_path = os.path.join( |
| 482 | self.chroot_path, self.sysroot_path.lstrip(os.sep) |
| 483 | ) |
| 484 | self.full_sysroot_package_path = os.path.join( |
| 485 | full_sysroot_path, "packages" |
| 486 | ) |
| 487 | osutils.SafeMakedirs(self.full_sysroot_package_path) |
| 488 | self.uploads_dir = os.path.join(self.tempdir, "uploads_dir") |
| 489 | osutils.SafeMakedirs(self.uploads_dir) |
| 490 | # Create packages/Packages file |
| 491 | packages_file = os.path.join(self.full_sysroot_package_path, "Packages") |
| 492 | packages_content = """\ |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 493 | USE: test |
| 494 | |
| 495 | CPV: app-arch/brotli-1.0.6 |
| 496 | |
| 497 | CPV: app-arch/zip-3.0-r3 |
| 498 | |
| 499 | CPV: chromeos-base/shill-0.0.1-r1 |
| 500 | |
| 501 | CPV: chromeos-base/test-0.0.1-r1 |
| 502 | |
| 503 | CPV: virtual/chromium-os-printing-1-r4 |
| 504 | |
| 505 | CPV: virtual/python-enum34-1 |
| 506 | |
| 507 | """ |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 508 | osutils.WriteFile(packages_file, packages_content) |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 509 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 510 | # Create package.installable file |
| 511 | self.dev_install_packages = [ |
| 512 | "app-arch/zip-3.0-r3", |
| 513 | "virtual/chromium-os-printing-1-r4", |
| 514 | "virtual/python-enum34-1", |
| 515 | ] |
| 516 | package_installable_dir = os.path.join( |
| 517 | full_sysroot_path, "build/dev-install" |
| 518 | ) |
| 519 | osutils.SafeMakedirs(package_installable_dir) |
| 520 | package_installable_filename = os.path.join( |
| 521 | package_installable_dir, "package.installable" |
| 522 | ) |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 523 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 524 | # Create path to the dev_install_packages |
| 525 | packages_dir = os.path.join(full_sysroot_path, "packages") |
| 526 | osutils.SafeMakedirs(packages_dir) |
| 527 | for package in self.dev_install_packages: |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 528 | # Since a package has a category, such as app-arch/zip-3.0-r3, we |
| 529 | # need to create the packages_dir / category dir as needed. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 530 | category = package.split(os.sep)[0] |
| 531 | osutils.SafeMakedirs(os.path.join(packages_dir, category)) |
| 532 | package_tbz2_file = os.path.join(packages_dir, package) + ".tbz2" |
| 533 | osutils.Touch(package_tbz2_file) |
| 534 | with open( |
Mike Frysinger | d97829b | 2023-02-24 16:09:20 -0500 | [diff] [blame] | 535 | package_installable_filename, "w", encoding="utf-8" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 536 | ) as package_installable_file: |
| 537 | for package in self.dev_install_packages: |
| 538 | package_installable_file.write(package + "\n") |
| 539 | self.response = binhost_pb2.PrepareDevInstallBinhostUploadsResponse() |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 540 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 541 | def testValidateOnly(self): |
| 542 | """Check that a validate only call does not execute any logic.""" |
| 543 | patch = self.PatchObject( |
| 544 | binhost_service, "ReadDevInstallFilesToCreatePackageIndex" |
| 545 | ) |
Michael Mortensen | fc82388 | 2019-08-27 14:38:07 -0600 | [diff] [blame] | 546 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 547 | input_proto = binhost_pb2.PrepareDevInstallBinhostUploadsRequest() |
| 548 | input_proto.uri = "gs://chromeos-prebuilt/target" |
| 549 | input_proto.chroot.path = self.chroot_path |
| 550 | input_proto.sysroot.path = self.sysroot_path |
| 551 | input_proto.uploads_dir = self.uploads_dir |
| 552 | binhost.PrepareDevInstallBinhostUploads( |
| 553 | input_proto, self.response, self.validate_only_config |
| 554 | ) |
| 555 | patch.assert_not_called() |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 556 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 557 | def testMockCall(self): |
Alex Klein | ab87ceb | 2023-01-24 12:00:51 -0700 | [diff] [blame] | 558 | """Test a mock call does not execute logic, returns mocked value.""" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 559 | patch = self.PatchObject( |
| 560 | binhost_service, "ReadDevInstallFilesToCreatePackageIndex" |
| 561 | ) |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 562 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 563 | input_proto = binhost_pb2.PrepareDevInstallBinhostUploadsRequest() |
| 564 | input_proto.uri = "gs://chromeos-prebuilt/target" |
| 565 | input_proto.chroot.path = self.chroot_path |
| 566 | input_proto.sysroot.path = self.sysroot_path |
| 567 | input_proto.uploads_dir = self.uploads_dir |
| 568 | binhost.PrepareDevInstallBinhostUploads( |
| 569 | input_proto, self.response, self.mock_call_config |
| 570 | ) |
| 571 | self.assertEqual(len(self.response.upload_targets), 3) |
| 572 | self.assertEqual(self.response.upload_targets[2].path, "Packages") |
| 573 | patch.assert_not_called() |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 574 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 575 | def testDevInstallerUpload(self): |
| 576 | """Test uploads of dev installer prebuilts.""" |
| 577 | # self.RunStage() |
| 578 | input_proto = binhost_pb2.PrepareDevInstallBinhostUploadsRequest() |
| 579 | input_proto.uri = "gs://chromeos-prebuilt/target" |
| 580 | input_proto.chroot.path = self.chroot_path |
| 581 | input_proto.sysroot.path = self.sysroot_path |
| 582 | input_proto.uploads_dir = self.uploads_dir |
| 583 | # Call method under test |
| 584 | binhost.PrepareDevInstallBinhostUploads( |
| 585 | input_proto, self.response, self.api_config |
| 586 | ) |
| 587 | # Verify results |
| 588 | expected_upload_targets = [ |
| 589 | "app-arch/zip-3.0-r3.tbz2", |
| 590 | "virtual/chromium-os-printing-1-r4.tbz2", |
| 591 | "virtual/python-enum34-1.tbz2", |
| 592 | "Packages", |
| 593 | ] |
| 594 | self.assertCountEqual( |
| 595 | [ut.path for ut in self.response.upload_targets], |
| 596 | expected_upload_targets, |
| 597 | ) |
| 598 | # All of the upload_targets should also be in the uploads_directory |
| 599 | for target in self.response.upload_targets: |
| 600 | self.assertExists( |
| 601 | os.path.join(input_proto.uploads_dir, target.path) |
| 602 | ) |
Michael Mortensen | 42251f9 | 2019-11-14 11:01:43 -0700 | [diff] [blame] | 603 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 604 | def testPrepareBinhostUploadsNonGsUri(self): |
| 605 | """PrepareBinhostUploads dies when URI does not point to GS.""" |
| 606 | input_proto = binhost_pb2.PrepareDevInstallBinhostUploadsRequest() |
| 607 | input_proto.chroot.path = self.chroot_path |
| 608 | input_proto.sysroot.path = self.sysroot_path |
| 609 | input_proto.uploads_dir = self.uploads_dir |
| 610 | input_proto.uri = "https://foo.bar" |
| 611 | with self.assertRaises(ValueError): |
| 612 | binhost.PrepareDevInstallBinhostUploads( |
| 613 | input_proto, self.response, self.api_config |
| 614 | ) |
Cindy Lin | d4c122a | 2023-04-13 19:09:31 +0000 | [diff] [blame^] | 615 | |
| 616 | |
| 617 | class PrepareChromeBinhostUploadsTest( |
| 618 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 619 | ): |
| 620 | """Tests for BinhostService/PrepareChromeBinhostUploads.""" |
| 621 | |
| 622 | def setUp(self): |
| 623 | self.PatchObject(cros_build_lib, "IsInsideChroot", return_value=False) |
| 624 | self.create_chrome_package_index_mock = self.PatchObject( |
| 625 | binhost_service, "CreateChromePackageIndex" |
| 626 | ) |
| 627 | |
| 628 | self.chroot_path = self.tempdir / "chroot" |
| 629 | self.sysroot_path = "build/target" |
| 630 | self.uploads_dir = self.tempdir / "uploads_dir" |
| 631 | self.input_proto = binhost_pb2.PrepareChromeBinhostUploadsRequest() |
| 632 | self.input_proto.uri = "gs://chromeos-prebuilt/target" |
| 633 | self.input_proto.chroot.path = str(self.chroot_path) |
| 634 | self.input_proto.sysroot.path = self.sysroot_path |
| 635 | self.input_proto.uploads_dir = str(self.uploads_dir) |
| 636 | self.response = binhost_pb2.PrepareChromeBinhostUploadsResponse() |
| 637 | |
| 638 | self.packages_path = self.chroot_path / self.sysroot_path / "packages" |
| 639 | self.chrome_packages_path = self.packages_path / constants.CHROME_CN |
| 640 | osutils.Touch( |
| 641 | self.chrome_packages_path / "chromeos-chrome-100-r1.tbz2", |
| 642 | makedirs=True, |
| 643 | ) |
| 644 | osutils.Touch( |
| 645 | self.chrome_packages_path / "chrome-icu-100-r1.tbz2", |
| 646 | makedirs=True, |
| 647 | ) |
| 648 | osutils.Touch( |
| 649 | self.chrome_packages_path / "chromeos-lacros-100-r1.tbz2", |
| 650 | makedirs=True, |
| 651 | ) |
| 652 | |
| 653 | def testValidateOnly(self): |
| 654 | """Check that a validate only call does not execute any logic.""" |
| 655 | binhost.PrepareChromeBinhostUploads( |
| 656 | self.input_proto, self.response, self.validate_only_config |
| 657 | ) |
| 658 | |
| 659 | self.create_chrome_package_index_mock.assert_not_called() |
| 660 | |
| 661 | def testMockCall(self): |
| 662 | """Test a mock call does not execute logic, returns mocked value.""" |
| 663 | binhost.PrepareChromeBinhostUploads( |
| 664 | self.input_proto, self.response, self.mock_call_config |
| 665 | ) |
| 666 | |
| 667 | self.assertEqual(len(self.response.upload_targets), 4) |
| 668 | self.assertEqual(self.response.upload_targets[3].path, "Packages") |
| 669 | self.create_chrome_package_index_mock.assert_not_called() |
| 670 | |
| 671 | def testChromeUpload(self): |
| 672 | """Test uploads of Chrome prebuilts.""" |
| 673 | expected_upload_targets = [ |
| 674 | "chromeos-base/chromeos-chrome-100-r1.tbz2", |
| 675 | "chromeos-base/chrome-icu-100-r1.tbz2", |
| 676 | "chromeos-base/chromeos-lacros-100-r1.tbz2", |
| 677 | ] |
| 678 | self.create_chrome_package_index_mock.return_value = ( |
| 679 | expected_upload_targets |
| 680 | ) |
| 681 | |
| 682 | binhost.PrepareChromeBinhostUploads( |
| 683 | self.input_proto, self.response, self.api_config |
| 684 | ) |
| 685 | |
| 686 | self.assertCountEqual( |
| 687 | [target.path for target in self.response.upload_targets], |
| 688 | expected_upload_targets + ["Packages"], |
| 689 | ) |
| 690 | |
| 691 | def testPrepareBinhostUploadsNonGsUri(self): |
| 692 | """PrepareBinhostUploads dies when URI does not point to GS.""" |
| 693 | self.input_proto.uri = "https://foo.bar" |
| 694 | |
| 695 | with self.assertRaises(ValueError): |
| 696 | binhost.PrepareChromeBinhostUploads( |
| 697 | self.input_proto, self.response, self.api_config |
| 698 | ) |