blob: 5afca40fc993954b890a9154ff1a3f6960eff140 [file] [log] [blame]
# Copyright 2021 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
from RECIPE_MODULES.fuchsia.buildbucket_util.api import BuildbucketUtilApi
class BuildbucketUtilTestApi(recipe_test_api.RecipeTestApi):
# Exposed for use in examples
MAX_SUMMARY_SIZE = BuildbucketUtilApi.MAX_SUMMARY_SIZE
def test(self, name, tryjob=False, status="SUCCESS", repo="fuchsia", **kwargs):
"""Returns a test case appropriate for yielding from GenTests().
Overrides the default mock build input provided by the recipe engine
with Fuchsia-specific data, which is more realistic for most recipes in
the fuchsia recipes repo.
Args:
name (str): Test name.
tryjob (bool): Whether the mocked Buildbucket input should contain
gerrit_changes.
status (str): Passed through to `api.test()`.
repo (str): Name of the git repo URL to set in the BuildBucket
input.
"""
ret = super().test(name, status=status)
kwargs.setdefault("git_repo", "https://fuchsia.googlesource.com/" + repo)
kwargs.setdefault("execution_timeout", 10 * 60 * 60)
# "project" here refers to LUCI project, not git/jiri project.
kwargs.setdefault("project", "fuchsia")
kwargs.setdefault("on_backend", True)
if tryjob:
ret += self.m.buildbucket.try_build(**kwargs)
else:
ret += self.m.buildbucket.ci_build(**kwargs)
return ret
def tryjob_branch(self, branch):
"""Mocks the branch name returned by `triggering_branch`.
Only valid for tests that mimic tryjobs, since the mocked step does not
run in CI.
"""
return self.step_data(
"resolve triggering ref.get change details",
self.m.json.output({"branch": branch}),
)