api: field_handler: Ignore empty ResultPath fields
If we add a ResultPath to a message but don't immediately start filling
it, extract_results() will still generate an empty destination path and
use it, generating response messages that the (unchanged) client won't
understand.
Only use the destination path if it's non-empty.
BUG=b:289353958
TEST=./run_tests
Change-Id: Ic3319ff8667d98074d7d37cd511d1c827d5419bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4655747
Commit-Queue: Brian Norris <briannorris@chromium.org>
Reviewed-by: Sergey Frolov <sfrolov@google.com>
Tested-by: Brian Norris <briannorris@chromium.org>
diff --git a/api/field_handler_unittest.py b/api/field_handler_unittest.py
index 665d1e2..192a895 100644
--- a/api/field_handler_unittest.py
+++ b/api/field_handler_unittest.py
@@ -5,6 +5,7 @@
"""field_handler module tests."""
import os
+from pathlib import Path
from chromite.api import field_handler
from chromite.api.gen.chromite.api import build_api_test_pb2
@@ -452,6 +453,24 @@
if contents:
self.assertFileContents(path, contents)
+ def test_empty_result_path(self):
+ """Test an empty result path.
+
+ Destination should be unchanged, and response message left as-is /
+ unfilled.
+ """
+ self.request.result_path.path.path = ""
+ self.response.artifact.path = self.source_file1_inside
+ self.response.artifact.location = common_pb2.Path.INSIDE
+
+ field_handler.extract_results(self.request, self.response, self.chroot)
+
+ self.assertEqual([], list(Path(self.dest_dir).iterdir()))
+ self.assertEqual(self.source_file1_inside, self.response.artifact.path)
+ self.assertEqual(
+ common_pb2.Path.INSIDE, self.response.artifact.location
+ )
+
def test_single_file(self):
"""Test a single file.