blob: 8fd7cdb0f8b9e90b24c21fe0e9442bdb0ce8d61e [file] [log] [blame]
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from recipe_engine import recipe_test_api
class CheckoutTestApi(recipe_test_api.RecipeTestApi):
def test(
self,
name,
tryjob=True,
properties=None,
patchfile=None,
status="success",
source_info=None,
):
"""Creates a CheckoutApi test case.
Args:
name (str): The name of this test case.
properties: Recipe properties. These will overwrite any defaults.
patchfile (Dict): JSON object representing the contents of a patchfile.
If unset, no patchfile will be present in this test.
status (str): One of 'success' (default), 'failure', or
'infra_failure'. The result of the test case will be required to
match this.
source_info (dict): jiri source info.
"""
if not properties:
properties = dict()
project = properties.get("project", "garnet")
# Create return value.
ret = self.m.status_check.test(name, status=status)
# Overwrite default properties with input properties.
ret += self.m.properties(**properties)
# Set buildbucket properties.
git_repo = "https://fuchsia.googlesource.com/" + project
if tryjob:
ret += self.m.buildbucket.try_build(
project=project,
git_repo=git_repo,
bucket=properties.get("bucket", "try"),
)
else:
ret += self.m.buildbucket.ci_build(
project=project,
git_repo=git_repo,
bucket=properties.get("bucket", "ci"),
)
# Add test patchfile if specified.
if patchfile is not None:
patchfile_path = self.m.path["start_dir"].join(
"fuchsia", project, "patches.json"
)
ret += self.m.path.exists(patchfile_path)
# TODO(tonglisayhi): Figure out a way to inject this step_data with
# whatever nesting this step is
ret += self.step_data(
"checkout.read patches-json", self.m.json.output(patchfile)
)
if source_info is not None:
ret += self.step_data(
"checkout.source-info", self.m.json.output(source_info),
)
return ret