Build API: Allow output with non-zero return codes.
BUG=None
TEST=run_tests
Change-Id: Iec5d02ced71755c3e97d611e2c269ae9e4479ac8
Reviewed-on: https://chromium-review.googlesource.com/1534542
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: Lann Martin <lannm@chromium.org>
diff --git a/scripts/build_api_unittest.py b/scripts/build_api_unittest.py
index aad9a08..efa1669 100644
--- a/scripts/build_api_unittest.py
+++ b/scripts/build_api_unittest.py
@@ -7,13 +7,16 @@
from __future__ import print_function
+import os
+
from chromite.api.gen.chromite.api import build_api_test_pb2
from chromite.lib import cros_build_lib
from chromite.lib import cros_test_lib
+from chromite.lib import osutils
from chromite.scripts import build_api
-class RouterTest(cros_test_lib.MockTestCase):
+class RouterTest(cros_test_lib.MockTempDirTestCase):
"""Test Router functionality."""
_INPUT_JSON = '{"id":"Input ID"}'
@@ -21,6 +24,11 @@
self.router = build_api.Router()
self.router.Register(build_api_test_pb2)
+ self.input_file = os.path.join(self.tempdir, 'input.json')
+ self.output_file = os.path.join(self.tempdir, 'output.json')
+
+ osutils.WriteFile(self.input_file, self._INPUT_JSON)
+
def testInputOutputMethod(self):
"""Test input/output handling."""
def impl(input_msg, output_msg):
@@ -30,7 +38,7 @@
self.PatchObject(self.router, '_GetMethod', return_value=impl)
self.router.Route('chromite.api.TestApiService', 'InputOutputMethod',
- self._INPUT_JSON)
+ self.input_file, self.output_file)
def testRenameMethod(self):
"""Test implementation name config."""
@@ -41,7 +49,7 @@
self.PatchObject(self.router, '_GetMethod', side_effect=_GetMethod)
self.router.Route('chromite.api.TestApiService', 'RenamedMethod',
- self._INPUT_JSON)
+ self.input_file, self.output_file)
def testInsideServiceChrootAsserts(self):
"""Test the chroot assertion handling with service inside configured."""
@@ -60,24 +68,28 @@
# Not inside chroot with inside requirement should raise an error.
with self.assertRaises(cros_build_lib.DieSystemExit):
self.router.Route('chromite.api.InsideChrootApiService',
- 'InsideServiceInsideMethod', self._INPUT_JSON)
+ 'InsideServiceInsideMethod', self.input_file,
+ self.output_file)
# Inside chroot with inside requirement.
is_inside = should_be_called = True
self.router.Route('chromite.api.InsideChrootApiService',
- 'InsideServiceInsideMethod', self._INPUT_JSON)
+ 'InsideServiceInsideMethod', self.input_file,
+ self.output_file)
# Inside chroot with outside override should raise assertion.
is_inside = True
should_be_called = False
with self.assertRaises(cros_build_lib.DieSystemExit):
self.router.Route('chromite.api.InsideChrootApiService',
- 'InsideServiceOutsideMethod', self._INPUT_JSON)
+ 'InsideServiceOutsideMethod', self.input_file,
+ self.output_file)
is_inside = False
should_be_called = True
self.router.Route('chromite.api.InsideChrootApiService',
- 'InsideServiceOutsideMethod', self._INPUT_JSON)
+ 'InsideServiceOutsideMethod', self.input_file,
+ self.output_file)
def testOutsideServiceChrootAsserts(self):
"""Test the chroot assertion handling with service outside configured."""
@@ -96,22 +108,26 @@
is_inside = False
should_be_called = True
self.router.Route('chromite.api.OutsideChrootApiService',
- 'OutsideServiceOutsideMethod', self._INPUT_JSON)
+ 'OutsideServiceOutsideMethod', self.input_file,
+ self.output_file)
# Inside chroot with outside requirement should raise error.
is_inside = True
should_be_called = False
with self.assertRaises(cros_build_lib.DieSystemExit):
self.router.Route('chromite.api.OutsideChrootApiService',
- 'OutsideServiceOutsideMethod', self._INPUT_JSON)
+ 'OutsideServiceOutsideMethod', self.input_file,
+ self.output_file)
# Outside chroot with inside override should raise error.
is_inside = should_be_called = False
with self.assertRaises(cros_build_lib.DieSystemExit):
self.router.Route('chromite.api.OutsideChrootApiService',
- 'OutsideServiceInsideMethod', self._INPUT_JSON)
+ 'OutsideServiceInsideMethod', self.input_file,
+ self.output_file)
# Inside chroot with inside override should be fine.
is_inside = should_be_called = True
self.router.Route('chromite.api.OutsideChrootApiService',
- 'OutsideServiceInsideMethod', self._INPUT_JSON)
+ 'OutsideServiceInsideMethod', self.input_file,
+ self.output_file)