Implement SimpleChromeWorkflowTest in the Test endpoint.

BUG=chromium:999670
TEST=manual, run_tests

Change-Id: If274a040a7326a2b5c4a0cf9d81808d59b665b4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1845358
Reviewed-by: Alex Klein <saklein@chromium.org>
Tested-by: Michael Mortensen <mmortensen@google.com>
Commit-Queue: Michael Mortensen <mmortensen@google.com>
diff --git a/api/controller/test_unittest.py b/api/controller/test_unittest.py
index 2289895..86f1b50 100644
--- a/api/controller/test_unittest.py
+++ b/api/controller/test_unittest.py
@@ -139,6 +139,75 @@
     self.assertFalse(self.rc.call_count)
 
 
+class SimpleChromeWorkflowTestTest(cros_test_lib.MockTestCase,
+                                   api_config.ApiConfigMixin):
+  """Test the SimpleChromeWorkflowTest endpoint."""
+
+  @staticmethod
+  def _Output():
+    return test_pb2.SimpleChromeWorkflowTestResponse()
+
+  def _Input(self, sysroot_path=None, build_target=None, chrome_root=None,
+             goma_config=None):
+    proto = test_pb2.SimpleChromeWorkflowTestRequest()
+    if sysroot_path:
+      proto.sysroot.path = sysroot_path
+    if build_target:
+      proto.sysroot.build_target.name = build_target
+    if chrome_root:
+      proto.chrome_root = chrome_root
+    if goma_config:
+      proto.goma_config = goma_config
+    return proto
+
+  def setUp(self):
+    self.chrome_path = 'path/to/chrome'
+    self.sysroot_dir = 'build/board'
+    self.build_target = 'amd64'
+    self.mock_simple_chrome_workflow_test = self.PatchObject(
+        test_service, 'SimpleChromeWorkflowTest')
+
+  def testMissingBuildTarget(self):
+    """Test VmTest dies when build_target not set."""
+    input_proto = self._Input(build_target=None, sysroot_path='/sysroot/dir',
+                              chrome_root='/chrome/path')
+    with self.assertRaises(cros_build_lib.DieSystemExit):
+      test_controller.SimpleChromeWorkflowTest(input_proto, None,
+                                               self.api_config)
+
+  def testMissingSysrootPath(self):
+    """Test VmTest dies when build_target not set."""
+    input_proto = self._Input(build_target='board', sysroot_path=None,
+                              chrome_root='/chrome/path')
+    with self.assertRaises(cros_build_lib.DieSystemExit):
+      test_controller.SimpleChromeWorkflowTest(input_proto, None,
+                                               self.api_config)
+
+  def testMissingChromeRoot(self):
+    """Test VmTest dies when build_target not set."""
+    input_proto = self._Input(build_target='board', sysroot_path='/sysroot/dir',
+                              chrome_root=None)
+    with self.assertRaises(cros_build_lib.DieSystemExit):
+      test_controller.SimpleChromeWorkflowTest(input_proto, None,
+                                               self.api_config)
+
+  def testSimpleChromeWorkflowTest(self):
+    """Call SimpleChromeWorkflowTest with valid args and temp dir."""
+    request = self._Input(sysroot_path='sysroot_path', build_target='board',
+                          chrome_root='/path/to/chrome')
+    response = self._Output()
+
+    test_controller.SimpleChromeWorkflowTest(request, response, self.api_config)
+    self.mock_simple_chrome_workflow_test.assert_called()
+
+  def testValidateOnly(self):
+    request = self._Input(sysroot_path='sysroot_path', build_target='board',
+                          chrome_root='/path/to/chrome')
+    test_controller.SimpleChromeWorkflowTest(request, self._Output(),
+                                             self.validate_only_config)
+    self.mock_simple_chrome_workflow_test.assert_not_called()
+
+
 class VmTestTest(cros_test_lib.RunCommandTestCase, api_config.ApiConfigMixin):
   """Test the VmTest endpoint."""