BuildAPI: Add unit tests for Test service ChromiteUnitTest and DebugInfoTest.
BUG=chromium:1029033
TEST=run_tests
Change-Id: If95bf3f9900ecae727b8627bdb699a1d9f558bb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1939775
Tested-by: Michael Mortensen <mmortensen@google.com>
Reviewed-by: Alex Klein <saklein@chromium.org>
Commit-Queue: Michael Mortensen <mmortensen@google.com>
diff --git a/api/controller/test_unittest.py b/api/controller/test_unittest.py
index 86f1b50..f28abf7 100644
--- a/api/controller/test_unittest.py
+++ b/api/controller/test_unittest.py
@@ -7,6 +7,8 @@
from __future__ import print_function
+import os
+
import contextlib
import mock
@@ -26,6 +28,53 @@
from chromite.utils import key_value_store
+class DebugInfoTestTest(cros_test_lib.MockTempDirTestCase,
+ api_config.ApiConfigMixin):
+ """Tests for the DebugInfoTest function."""
+
+ def setUp(self):
+ self.board = 'board'
+ self.chroot_path = os.path.join(self.tempdir, 'chroot')
+ self.sysroot_path = '/build/board'
+ self.full_sysroot_path = os.path.join(self.chroot_path,
+ self.sysroot_path.lstrip(os.sep))
+ osutils.SafeMakedirs(self.full_sysroot_path)
+
+ def _GetInput(self, sysroot_path=None, build_target=None):
+ """Helper to build an input message instance."""
+ proto = test_pb2.DebugInfoTestRequest()
+ if sysroot_path:
+ proto.sysroot.path = sysroot_path
+ if build_target:
+ proto.sysroot.build_target.name = build_target
+ return proto
+
+ def _GetOutput(self):
+ """Helper to get an empty output message instance."""
+ return test_pb2.DebugInfoTestResponse()
+
+ def testValidateOnly(self):
+ """Sanity check that a validate only call does not execute any logic."""
+ patch = self.PatchObject(test_service, 'DebugInfoTest')
+ input_msg = self._GetInput(sysroot_path=self.full_sysroot_path)
+ test_controller.DebugInfoTest(input_msg, self._GetOutput(),
+ self.validate_only_config)
+ patch.assert_not_called()
+
+ def testNoBuildTargetNoSysrootFails(self):
+ """Test missing build target name and sysroot path fails."""
+ input_msg = self._GetInput()
+ output_msg = self._GetOutput()
+ with self.assertRaises(cros_build_lib.DieSystemExit):
+ test_controller.DebugInfoTest(input_msg, output_msg, self.api_config)
+
+ def testDebugInfoTest(self):
+ """Call DebugInfoTest with valid sysroot_path."""
+ request = self._GetInput(sysroot_path=self.full_sysroot_path)
+
+ test_controller.DebugInfoTest(request, self._GetOutput(), self.api_config)
+
+
class BuildTargetUnitTestTest(cros_test_lib.MockTempDirTestCase,
api_config.ApiConfigMixin):
"""Tests for the UnitTest function."""
@@ -129,6 +178,46 @@
self.assertFalse(output_msg.failed_packages)
+class ChromiteUnitTestTest(cros_test_lib.MockTestCase,
+ api_config.ApiConfigMixin):
+ """Tests for the ChromiteInfoTest function."""
+
+ def setUp(self):
+ self.board = 'board'
+ self.chroot_path = '/path/to/chroot'
+
+ def _GetInput(self, chroot_path=None):
+ """Helper to build an input message instance."""
+ proto = test_pb2.ChromiteUnitTestRequest(
+ chroot={'path': chroot_path},
+ )
+ return proto
+
+ def _GetOutput(self):
+ """Helper to get an empty output message instance."""
+ return test_pb2.ChromiteUnitTestResponse()
+
+ def testValidateOnly(self):
+ """Sanity check that a validate only call does not execute any logic."""
+ patch = self.PatchObject(cros_build_lib, 'run')
+
+ input_msg = self._GetInput(chroot_path=self.chroot_path)
+ test_controller.ChromiteUnitTest(input_msg, self._GetOutput(),
+ self.validate_only_config)
+ patch.assert_not_called()
+
+ def testChromiteUnitTest(self):
+ """Call ChromiteUnitTest with mocked cros_build_lib.run."""
+ request = self._GetInput(chroot_path=self.chroot_path)
+ patch = self.PatchObject(
+ cros_build_lib, 'run',
+ return_value=cros_build_lib.CommandResult(returncode=0))
+
+ test_controller.ChromiteUnitTest(request, self._GetOutput(),
+ self.api_config)
+ patch.assert_called_once()
+
+
class CrosSigningTestTest(cros_test_lib.RunCommandTestCase,
api_config.ApiConfigMixin):
"""CrosSigningTest tests."""