blob: 5cf8489451715a59b1ace72d2671b506368bb0ba [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2019 The ChromiumOS Authors
Alex Klein19c4cc42019-02-27 14:47:57 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""SDK tests."""
6
Greg Edelston9dcdc8a2023-01-11 17:07:10 -07007import os
Greg Edelston01ae5942023-01-30 16:26:54 -07008import pathlib
Greg Edelston9dcdc8a2023-01-11 17:07:10 -07009from typing import List, Optional
Mike Frysinger166fea02021-02-12 05:30:33 -050010from unittest import mock
11
Alex Klein231d2da2019-07-22 16:44:45 -060012from chromite.api import api_config
Greg Edelston9dcdc8a2023-01-11 17:07:10 -070013from chromite.api.controller import controller_util
Alex Klein19c4cc42019-02-27 14:47:57 -070014from chromite.api.controller import sdk as sdk_controller
Alex Klein7107bdd2019-03-14 17:14:31 -060015from chromite.api.gen.chromite.api import sdk_pb2
Greg Edelston9dcdc8a2023-01-11 17:07:10 -070016from chromite.api.gen.chromiumos import common_pb2
17from chromite.lib import constants
Alex Klein19c4cc42019-02-27 14:47:57 -070018from chromite.lib import cros_build_lib
Alex Klein231d2da2019-07-22 16:44:45 -060019from chromite.lib import cros_test_lib
Alex Klein19c4cc42019-02-27 14:47:57 -070020from chromite.service import sdk as sdk_service
21
22
Alex Klein231d2da2019-07-22 16:44:45 -060023class SdkCreateTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
Alex Klein1699fab2022-09-08 08:46:06 -060024 """Create tests."""
Alex Klein19c4cc42019-02-27 14:47:57 -070025
Alex Klein1699fab2022-09-08 08:46:06 -060026 def setUp(self):
27 """Setup method."""
28 # We need to run the command outside the chroot.
29 self.PatchObject(cros_build_lib, "IsInsideChroot", return_value=False)
30 self.response = sdk_pb2.CreateResponse()
Alex Klein19c4cc42019-02-27 14:47:57 -070031
Alex Klein1699fab2022-09-08 08:46:06 -060032 def _GetRequest(
33 self,
34 no_replace=False,
Chris McDonald5dcdb892020-02-07 15:10:46 -070035 bootstrap=False,
Alex Klein1699fab2022-09-08 08:46:06 -060036 cache_path=None,
37 chroot_path=None,
38 sdk_version=None,
39 skip_chroot_upgrade=False,
40 ):
41 """Helper to build a create request message."""
42 request = sdk_pb2.CreateRequest()
43 request.flags.no_replace = no_replace
44 request.flags.bootstrap = bootstrap
Alex Klein231d2da2019-07-22 16:44:45 -060045
Alex Klein1699fab2022-09-08 08:46:06 -060046 if cache_path:
47 request.chroot.cache_dir = cache_path
48 if chroot_path:
49 request.chroot.path = chroot_path
50 if sdk_version:
51 request.sdk_version = sdk_version
52 if skip_chroot_upgrade:
53 request.skip_chroot_upgrade = skip_chroot_upgrade
Alex Klein19c4cc42019-02-27 14:47:57 -070054
Alex Klein1699fab2022-09-08 08:46:06 -060055 return request
56
57 def testValidateOnly(self):
Alex Kleinab87ceb2023-01-24 12:00:51 -070058 """Verify a validate-only call does not execute any logic."""
Alex Klein1699fab2022-09-08 08:46:06 -060059 patch = self.PatchObject(sdk_service, "Create")
60
61 sdk_controller.Create(
62 self._GetRequest(), self.response, self.validate_only_config
63 )
64 patch.assert_not_called()
65
66 def testMockCall(self):
67 """Sanity check that a mock call does not execute any logic."""
68 patch = self.PatchObject(sdk_service, "Create")
69
70 rc = sdk_controller.Create(
71 self._GetRequest(), self.response, self.mock_call_config
72 )
73 patch.assert_not_called()
74 self.assertFalse(rc)
75 self.assertTrue(self.response.version.version)
76
77 def testSuccess(self):
78 """Test the successful call output handling."""
79 self.PatchObject(sdk_service, "Create", return_value=1)
80
81 request = self._GetRequest()
82
83 sdk_controller.Create(request, self.response, self.api_config)
84
85 self.assertEqual(1, self.response.version.version)
86
87 def testFalseArguments(self):
88 """Test False argument handling."""
89 # Create the patches.
90 self.PatchObject(sdk_service, "Create", return_value=1)
91 args_patch = self.PatchObject(sdk_service, "CreateArguments")
92
93 # Flag translation tests.
94 # Test all false values in the message.
95 request = self._GetRequest(
Brian Norris35a7ed02023-02-23 12:50:14 -080096 no_replace=False,
97 bootstrap=False,
Alex Klein1699fab2022-09-08 08:46:06 -060098 )
99 sdk_controller.Create(request, self.response, self.api_config)
100 args_patch.assert_called_with(
101 replace=True,
102 bootstrap=False,
Alex Klein1699fab2022-09-08 08:46:06 -0600103 chroot_path=mock.ANY,
104 cache_dir=mock.ANY,
105 sdk_version=mock.ANY,
106 skip_chroot_upgrade=mock.ANY,
107 )
108
109 def testTrueArguments(self):
110 """Test True arguments handling."""
111 # Create the patches.
112 self.PatchObject(sdk_service, "Create", return_value=1)
113 args_patch = self.PatchObject(sdk_service, "CreateArguments")
114
115 # Test all True values in the message.
116 request = self._GetRequest(
117 no_replace=True,
118 bootstrap=True,
Alex Klein1699fab2022-09-08 08:46:06 -0600119 sdk_version="foo",
120 skip_chroot_upgrade=True,
121 )
122 sdk_controller.Create(request, self.response, self.api_config)
123 args_patch.assert_called_with(
124 replace=False,
125 bootstrap=True,
Alex Klein1699fab2022-09-08 08:46:06 -0600126 chroot_path=mock.ANY,
127 cache_dir=mock.ANY,
128 sdk_version="foo",
129 skip_chroot_upgrade=True,
130 )
Mike Frysingercb8992a2020-02-11 05:13:13 +0000131
Alex Kleinaa5c4172019-02-27 17:12:20 -0700132
Michael Mortensene87d8a62020-07-06 11:44:35 -0600133class SdkDeleteTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
Alex Klein1699fab2022-09-08 08:46:06 -0600134 """Create tests."""
Michael Mortensene87d8a62020-07-06 11:44:35 -0600135
Alex Klein1699fab2022-09-08 08:46:06 -0600136 def setUp(self):
137 """Setup method."""
138 # We need to run the command outside the chroot.
139 self.PatchObject(cros_build_lib, "IsInsideChroot", return_value=False)
140 self.response = sdk_pb2.DeleteResponse()
Michael Mortensene87d8a62020-07-06 11:44:35 -0600141
Alex Klein1699fab2022-09-08 08:46:06 -0600142 def _GetRequest(self, chroot_path=None):
143 """Helper to build a delete request message."""
144 request = sdk_pb2.DeleteRequest()
145 if chroot_path:
146 request.chroot.path = chroot_path
Michael Mortensene87d8a62020-07-06 11:44:35 -0600147
Alex Klein1699fab2022-09-08 08:46:06 -0600148 return request
Michael Mortensene87d8a62020-07-06 11:44:35 -0600149
Alex Klein1699fab2022-09-08 08:46:06 -0600150 def testValidateOnly(self):
Alex Kleinab87ceb2023-01-24 12:00:51 -0700151 """Verify a validate-only call does not execute any logic."""
Alex Klein1699fab2022-09-08 08:46:06 -0600152 patch = self.PatchObject(sdk_service, "Delete")
Michael Mortensene87d8a62020-07-06 11:44:35 -0600153
Alex Klein1699fab2022-09-08 08:46:06 -0600154 sdk_controller.Delete(
155 self._GetRequest(), self.response, self.validate_only_config
156 )
157 patch.assert_not_called()
Michael Mortensene87d8a62020-07-06 11:44:35 -0600158
Alex Klein1699fab2022-09-08 08:46:06 -0600159 def testMockCall(self):
160 """Sanity check that a mock call does not execute any logic."""
161 patch = self.PatchObject(sdk_service, "Delete")
Michael Mortensene87d8a62020-07-06 11:44:35 -0600162
Alex Klein1699fab2022-09-08 08:46:06 -0600163 rc = sdk_controller.Delete(
164 self._GetRequest(), self.response, self.mock_call_config
165 )
166 patch.assert_not_called()
167 self.assertFalse(rc)
Michael Mortensene87d8a62020-07-06 11:44:35 -0600168
Alex Klein1699fab2022-09-08 08:46:06 -0600169 def testSuccess(self):
170 """Test the successful call by verifying service invocation."""
171 patch = self.PatchObject(sdk_service, "Delete", return_value=1)
Michael Mortensene87d8a62020-07-06 11:44:35 -0600172
Alex Klein1699fab2022-09-08 08:46:06 -0600173 request = self._GetRequest()
Michael Mortensene87d8a62020-07-06 11:44:35 -0600174
Alex Klein1699fab2022-09-08 08:46:06 -0600175 sdk_controller.Delete(request, self.response, self.api_config)
176 # Verify that by default sdk_service.Delete is called with force=True.
177 patch.assert_called_once_with(mock.ANY, force=True)
Michael Mortensene87d8a62020-07-06 11:44:35 -0600178
179
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600180class SdkUnmountPathTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
Alex Klein1699fab2022-09-08 08:46:06 -0600181 """Update tests."""
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600182
Alex Klein1699fab2022-09-08 08:46:06 -0600183 def setUp(self):
184 """Setup method."""
185 self.response = sdk_pb2.UnmountPathResponse()
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600186
Alex Klein1699fab2022-09-08 08:46:06 -0600187 def _UnmountPathRequest(self, path=None):
188 """Helper to build a delete request message."""
189 request = sdk_pb2.UnmountPathRequest()
190 if path:
191 request.path.path = path
192 return request
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600193
Alex Klein1699fab2022-09-08 08:46:06 -0600194 def testValidateOnly(self):
Alex Kleinab87ceb2023-01-24 12:00:51 -0700195 """Verify a validate-only call does not execute any logic."""
Alex Klein1699fab2022-09-08 08:46:06 -0600196 patch = self.PatchObject(sdk_service, "UnmountPath")
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600197
Alex Klein1699fab2022-09-08 08:46:06 -0600198 sdk_controller.UnmountPath(
199 self._UnmountPathRequest("/test/path"),
200 self.response,
201 self.validate_only_config,
202 )
203 patch.assert_not_called()
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600204
Alex Klein1699fab2022-09-08 08:46:06 -0600205 def testMockCall(self):
206 """Sanity check that a mock call does not execute any logic."""
207 patch = self.PatchObject(sdk_service, "UnmountPath")
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600208
Alex Klein1699fab2022-09-08 08:46:06 -0600209 rc = sdk_controller.UnmountPath(
210 self._UnmountPathRequest(), self.response, self.mock_call_config
211 )
212 patch.assert_not_called()
213 self.assertFalse(rc)
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600214
Alex Klein1699fab2022-09-08 08:46:06 -0600215 def testSuccess(self):
216 """Test the successful call by verifying service invocation."""
217 patch = self.PatchObject(sdk_service, "UnmountPath", return_value=1)
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600218
Alex Klein1699fab2022-09-08 08:46:06 -0600219 request = self._UnmountPathRequest("/test/path")
220 sdk_controller.UnmountPath(request, self.response, self.api_config)
221 patch.assert_called_once_with("/test/path")
Michael Mortensen52a98ac2020-07-28 16:00:18 -0600222
223
Alex Klein231d2da2019-07-22 16:44:45 -0600224class SdkUpdateTest(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
Alex Klein1699fab2022-09-08 08:46:06 -0600225 """Update tests."""
Alex Kleinaa5c4172019-02-27 17:12:20 -0700226
Alex Klein1699fab2022-09-08 08:46:06 -0600227 def setUp(self):
228 """Setup method."""
229 # We need to run the command inside the chroot.
230 self.PatchObject(cros_build_lib, "IsInsideChroot", return_value=True)
Alex Kleinaa5c4172019-02-27 17:12:20 -0700231
Alex Klein1699fab2022-09-08 08:46:06 -0600232 self.response = sdk_pb2.UpdateResponse()
Alex Klein231d2da2019-07-22 16:44:45 -0600233
Alex Klein1699fab2022-09-08 08:46:06 -0600234 def _GetRequest(self, build_source=False, targets=None):
235 """Helper to simplify building a request instance."""
236 request = sdk_pb2.UpdateRequest()
237 request.flags.build_source = build_source
Alex Kleinaa5c4172019-02-27 17:12:20 -0700238
Alex Klein1699fab2022-09-08 08:46:06 -0600239 for target in targets or []:
240 added = request.toolchain_targets.add()
241 added.name = target
Alex Kleinaa5c4172019-02-27 17:12:20 -0700242
Alex Klein1699fab2022-09-08 08:46:06 -0600243 return request
Alex Kleinaa5c4172019-02-27 17:12:20 -0700244
Alex Klein1699fab2022-09-08 08:46:06 -0600245 def testValidateOnly(self):
Alex Kleinab87ceb2023-01-24 12:00:51 -0700246 """Verify a validate-only call does not execute any logic."""
Alex Klein1699fab2022-09-08 08:46:06 -0600247 patch = self.PatchObject(sdk_service, "Update")
Alex Klein231d2da2019-07-22 16:44:45 -0600248
Alex Klein1699fab2022-09-08 08:46:06 -0600249 sdk_controller.Update(
250 self._GetRequest(), self.response, self.validate_only_config
251 )
252 patch.assert_not_called()
Alex Kleinaa5c4172019-02-27 17:12:20 -0700253
Alex Klein1699fab2022-09-08 08:46:06 -0600254 def testMockCall(self):
255 """Sanity check that a mock call does not execute any logic."""
256 patch = self.PatchObject(sdk_service, "Update")
Alex Klein076841b2019-08-29 15:19:39 -0600257
Alex Klein1699fab2022-09-08 08:46:06 -0600258 rc = sdk_controller.Create(
259 self._GetRequest(), self.response, self.mock_call_config
260 )
261 patch.assert_not_called()
262 self.assertFalse(rc)
263 self.assertTrue(self.response.version.version)
Alex Klein076841b2019-08-29 15:19:39 -0600264
Alex Klein1699fab2022-09-08 08:46:06 -0600265 def testSuccess(self):
266 """Successful call output handling test."""
267 expected_version = 1
268 self.PatchObject(sdk_service, "Update", return_value=expected_version)
269 request = self._GetRequest()
Alex Kleinaa5c4172019-02-27 17:12:20 -0700270
Alex Klein1699fab2022-09-08 08:46:06 -0600271 sdk_controller.Update(request, self.response, self.api_config)
Alex Kleinaa5c4172019-02-27 17:12:20 -0700272
Alex Klein1699fab2022-09-08 08:46:06 -0600273 self.assertEqual(expected_version, self.response.version.version)
Alex Kleinaa5c4172019-02-27 17:12:20 -0700274
Alex Klein1699fab2022-09-08 08:46:06 -0600275 def testArgumentHandling(self):
276 """Test the proto argument handling."""
277 args = sdk_service.UpdateArguments()
278 self.PatchObject(sdk_service, "Update", return_value=1)
279 args_patch = self.PatchObject(
280 sdk_service, "UpdateArguments", return_value=args
281 )
Alex Kleinaa5c4172019-02-27 17:12:20 -0700282
Alex Klein1699fab2022-09-08 08:46:06 -0600283 # No boards and flags False.
284 request = self._GetRequest(build_source=False)
285 sdk_controller.Update(request, self.response, self.api_config)
286 args_patch.assert_called_with(
287 build_source=False, toolchain_targets=[], toolchain_changed=False
288 )
Alex Kleinaa5c4172019-02-27 17:12:20 -0700289
Alex Klein1699fab2022-09-08 08:46:06 -0600290 # Multiple boards and flags True.
291 targets = ["board1", "board2"]
292 request = self._GetRequest(build_source=True, targets=targets)
293 sdk_controller.Update(request, self.response, self.api_config)
294 args_patch.assert_called_with(
295 build_source=True,
296 toolchain_targets=targets,
297 toolchain_changed=False,
298 )
Greg Edelston9dcdc8a2023-01-11 17:07:10 -0700299
300
Greg Edelston01ae5942023-01-30 16:26:54 -0700301class CreateManifestFromSdkTest(
302 cros_test_lib.MockTestCase, api_config.ApiConfigMixin
303):
304 """Test the SdkService/CreateManifestFromSdk endpoint."""
305
306 _chroot_path = "/path/to/chroot"
307 _sdk_path_relative = "build/my_sdk"
308 _dest_dir = "/build"
309 _manifest_path = "/build/my_sdk.Manifest"
310
311 def _NewRequest(self, inside: bool) -> sdk_pb2.CreateManifestFromSdkRequest:
312 return sdk_pb2.CreateManifestFromSdkRequest(
313 chroot=common_pb2.Chroot(path=self._chroot_path),
314 sdk_path=common_pb2.Path(
315 path="/%s" % self._sdk_path_relative,
316 location=common_pb2.Path.Location.INSIDE
317 if inside
318 else common_pb2.Path.Location.OUTSIDE,
319 ),
320 dest_dir=common_pb2.Path(
321 path=self._dest_dir,
322 location=common_pb2.Path.Location.OUTSIDE,
323 ),
324 )
325
326 def _NewResponse(self) -> sdk_pb2.CreateManifestFromSdkResponse:
327 return sdk_pb2.CreateManifestFromSdkResponse()
328
329 def testValidateOnly(self):
330 """Check that a validate only call does not execute any logic."""
331 impl_patch = self.PatchObject(sdk_service, "CreateManifestFromSdk")
332 sdk_controller.BuildSdkToolchain(
333 self._NewRequest(False),
334 self._NewResponse(),
335 self.validate_only_config,
336 )
337 impl_patch.assert_not_called()
338
339 def testOutside(self):
340 """Check that a call with an outside path succeeds."""
341 impl_patch = self.PatchObject(
342 sdk_service,
343 "CreateManifestFromSdk",
344 return_value=pathlib.Path(self._manifest_path),
345 )
346 request = self._NewRequest(inside=False)
347 response = self._NewResponse()
348 sdk_controller.CreateManifestFromSdk(
349 request,
350 response,
351 self.api_config,
352 )
353 impl_patch.assert_called_with(
354 pathlib.Path("/", self._sdk_path_relative),
355 pathlib.Path(self._dest_dir),
356 )
357 self.assertEqual(
358 response.manifest_path.location, common_pb2.Path.Location.OUTSIDE
359 )
360 self.assertEqual(response.manifest_path.path, self._manifest_path)
361
362 def testInside(self):
363 """Check that an inside path parses correctly and the call succeeds."""
364 impl_patch = self.PatchObject(
365 sdk_service,
366 "CreateManifestFromSdk",
367 return_value=pathlib.Path(self._manifest_path),
368 )
369 request = self._NewRequest(inside=True)
370 response = self._NewResponse()
371 sdk_controller.CreateManifestFromSdk(
372 request,
373 response,
374 self.api_config,
375 )
376 impl_patch.assert_called_with(
377 pathlib.Path(self._chroot_path, self._sdk_path_relative),
378 pathlib.Path(self._dest_dir),
379 )
380 self.assertEqual(
381 response.manifest_path.location, common_pb2.Path.Location.OUTSIDE
382 )
383 self.assertEqual(response.manifest_path.path, self._manifest_path)
384
385
Greg Edelston9dcdc8a2023-01-11 17:07:10 -0700386class BuildSdkToolchainTest(
387 cros_test_lib.MockTestCase, api_config.ApiConfigMixin
388):
389 """Test the SdkService/BuildSdkToolchain endpoint."""
390
391 def setUp(self):
392 """Set up the test case."""
393 self._chroot_path = "/path/to/chroot"
394 self._response = sdk_pb2.BuildSdkToolchainResponse()
395 self._generated_filenames = (
396 "armv7a-cros-linux-gnueabihf.tar.xz",
397 "x86_64-cros-linux-gnu.tar.xz",
398 )
399 self._paths_for_generated_files = [
400 common_pb2.Path(
401 path=os.path.join(constants.SDK_TOOLCHAINS_OUTPUT, fname),
402 location=common_pb2.Path.Location.INSIDE,
403 )
404 for fname in self._generated_filenames
405 ]
406
407 def _NewRequest(
408 self,
409 chroot_path: Optional[str] = None,
410 use_flags: Optional[List[str]] = None,
411 ) -> sdk_pb2.BuildSdkToolchainRequest:
412 """Return a new BuildSdkToolchainRequest message."""
413 request = sdk_pb2.BuildSdkToolchainRequest()
414 if chroot_path:
415 request.chroot.path = chroot_path
416 if use_flags:
417 request.use_flags.extend(
418 common_pb2.UseFlag(flag=flag) for flag in use_flags
419 )
420 return request
421
422 def _NewResponse(
423 self, generated_filenames: Optional[List[str]] = None
424 ) -> sdk_pb2.BuildSdkToolchainResponse:
425 """Return a new BuildSdkToolchainResponse message."""
426 response = sdk_pb2.BuildSdkToolchainResponse()
427 if generated_filenames:
428 response.generated_files.extend(
429 common_pb2.Path(
430 path=os.path.join(constants.SDK_TOOLCHAINS_OUTPUT, fname),
431 location=common_pb2.Path.Location.INSIDE,
432 )
433 for fname in generated_filenames
434 )
435 return response
436
437 def testValidateOnly(self):
438 """Check that a validate only call does not execute any logic."""
439 impl_patch = self.PatchObject(sdk_service, "BuildSdkToolchain")
440 sdk_controller.BuildSdkToolchain(
441 self._NewRequest(), self._NewResponse(), self.validate_only_config
442 )
443 impl_patch.assert_not_called()
444
445 def testSuccess(self):
446 """Check that a normal call defers to the SDK service as expected."""
447 impl_patch = self.PatchObject(sdk_service, "BuildSdkToolchain")
448 request = self._NewRequest(use_flags=[])
449 response = self._NewResponse()
450 sdk_controller.BuildSdkToolchain(
451 request,
452 response,
453 self.api_config,
454 )
455 # Can't use assert_called_with, since the chroot objects are equal but
456 # not identical.
457 impl_patch.assert_called_once()
458 self.assertEqual(
459 impl_patch.call_args.args[0],
460 controller_util.ParseChroot(request.chroot),
461 )
462 self.assertEqual(impl_patch.call_args.kwargs["extra_env"], {})
463
464 def testSuccessWithUseFlags(self):
465 """Check that a call with USE flags works as expected."""
466 impl_patch = self.PatchObject(sdk_service, "BuildSdkToolchain")
467 request = self._NewRequest(use_flags=["llvm-next", "another-flag"])
468 response = self._NewResponse()
469 sdk_controller.BuildSdkToolchain(
470 request,
471 response,
472 self.api_config,
473 )
474 # Can't use assert_called_with, since the chroot objects are equal but
475 # not identical.
476 impl_patch.assert_called_once()
477 self.assertEqual(
478 impl_patch.call_args.args[0],
479 controller_util.ParseChroot(request.chroot),
480 )
481 self.assertEqual(
482 impl_patch.call_args.kwargs["extra_env"],
483 {"USE": "llvm-next another-flag"},
484 )
Greg Edelston6733dc52023-02-15 15:20:07 -0700485
486
487class UprevTestCase(cros_test_lib.MockTestCase, api_config.ApiConfigMixin):
488 """Test case for SdkService/Uprev() endpoint."""
489
490 _chroot_path = "/path/to/chroot"
491 _binhost_gs_bucket = "gs://chromiumos-prebuilts/"
492 _latest_version = "2023.02.15.115707"
493
494 def setUp(self):
495 """Set up the test case."""
496 self._chroot_pb2 = common_pb2.Chroot(path=self._chroot_path)
497 self._chroot = controller_util.ParseChroot(self._chroot_pb2)
498 self.PatchObject(
499 sdk_service,
500 "GetLatestVersion",
501 return_value=self._latest_version,
502 )
503 self._uprev_patch = self.PatchObject(
504 sdk_service,
505 "UprevSdkAndPrebuilts",
506 )
507
508 def NewRequest(self, version: str = ""):
509 """Return a new UprevRequest with standard inputs."""
510 return sdk_pb2.UprevRequest(
511 chroot=self._chroot_pb2,
512 binhost_gs_bucket=self._binhost_gs_bucket,
513 version=version,
514 )
515
516 @staticmethod
517 def NewResponse() -> sdk_pb2.UprevResponse:
518 """Return a new empty UprevResponse."""
519 return sdk_pb2.UprevResponse()
520
521 def testWithVersion(self):
522 """Test the endpoint with `version` specified.
523
524 In this case, we expect that sdk_controller.Uprev is called with the
525 version specified in the UprevRequest.
526 """
527 specified_version = "1970.01.01.000000"
528 request = self.NewRequest(version=specified_version)
529 response = self.NewResponse()
530 sdk_controller.Uprev(request, response, self.api_config)
531 self._uprev_patch.assert_called_with(
532 self._chroot,
533 binhost_gs_bucket=self._binhost_gs_bucket,
534 version=specified_version,
535 )
536
537 def testWithoutVersion(self):
538 """Test the endpoint with `version` not specified.
539
540 In this case, we expect that sdk_controller.Uprev is called with the
541 latest version available on gs://. This is fetched via
542 sdk_controller.GetLatestVersion (mocked here in setUp()).
543 """
544 request = self.NewRequest()
545 response = self.NewResponse()
546 sdk_controller.Uprev(request, response, self.api_config)
547 self._uprev_patch.assert_called_with(
548 self._chroot,
549 binhost_gs_bucket=self._binhost_gs_bucket,
550 version=self._latest_version,
551 )