binhost: add RegenBuildCache
BUG=chromium:904943 b:127692338
TEST=Unit tests pass.
CQ-DEPEND=CL:1568126
Change-Id: I8ba888e802810ac48de2e9fef71da0872f286d19
Reviewed-on: https://chromium-review.googlesource.com/1567463
Commit-Ready: LaMont Jones <lamontjones@chromium.org>
Tested-by: LaMont Jones <lamontjones@chromium.org>
Reviewed-by: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/binhost_unittest.py b/api/controller/binhost_unittest.py
index 7da19ed..0738e1b 100644
--- a/api/controller/binhost_unittest.py
+++ b/api/controller/binhost_unittest.py
@@ -7,10 +7,9 @@
from __future__ import print_function
-import mock
-
from chromite.api.controller import binhost
from chromite.api.gen.chromite.api import binhost_pb2
+from chromite.lib import cros_build_lib
from chromite.lib import cros_test_lib
from chromite.service import binhost as binhost_service
@@ -66,7 +65,35 @@
binhost.SetBinhost(input_proto, output_proto)
self.assertEqual(output_proto.output_file, '/path/to/BINHOST.conf')
- self.assertEqual(
- set_binhost.call_args_list,
- [mock.call('target', 'POSTSUBMIT_BINHOST',
- 'gs://chromeos-prebuilt/target', private=True)])
+ set_binhost.assert_called_once_with(
+ 'target', 'POSTSUBMIT_BINHOST', 'gs://chromeos-prebuilt/target',
+ private=True)
+
+class RegenBuildCacheTest(cros_test_lib.MockTestCase):
+ """Unittests for RegenBuildCache."""
+
+ def testRegenBuildCache(self):
+ """RegenBuildCache calls service with the correct args."""
+ regen_cache = self.PatchObject(binhost_service, 'RegenBuildCache')
+
+ input_proto = binhost_pb2.RegenBuildCacheRequest()
+ input_proto.overlay_type = binhost_pb2.OVERLAYTYPE_BOTH
+ input_proto.sysroot.path = '/path/to/chroot'
+ input_proto.sysroot.build_target.name = 'target'
+
+ binhost.RegenBuildCache(input_proto)
+ regen_cache.assert_called_once_with('both', '/path/to/chroot')
+
+ def testRequiresOverlayType(self):
+ """RegenBuildCache dies if overlay_type not specified."""
+ regen_cache = self.PatchObject(binhost_service, 'RegenBuildCache')
+ die = self.PatchObject(cros_build_lib, 'Die')
+
+ input_proto = binhost_pb2.RegenBuildCacheRequest()
+ input_proto.overlay_type = binhost_pb2.OVERLAYTYPE_UNSPECIFIED
+ input_proto.sysroot.path = '/path/to/chroot'
+ input_proto.sysroot.build_target.name = 'target'
+
+ binhost.RegenBuildCache(input_proto)
+ die.assert_called_once()
+ regen_cache.assert_not_called()