| # 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 FuchsiaTestApi(recipe_test_api.RecipeTestApi): |
| |
| DEFAULT_GCS_BUCKET = "###fuchsia-build###" |
| |
| def test( |
| self, |
| name, |
| clear_default_properties=False, |
| tryjob=False, |
| properties=None, |
| status="success", |
| steps=(), |
| ): # pragma: no cover |
| """Returns a test case appropriate for yielding from GenTests(). |
| |
| Provides default property values for the common cases. |
| |
| Args: |
| name: Test name. |
| clear_default_properties: If true, does not provide default values. |
| However, setting tryjob=True does still add the tryjob-related |
| properties. Buildbucket properties are always added. |
| tryjob: If true, adds tryjob-related properties. |
| properties: A required dict of properties to override for this test. |
| steps: An optional sequence of RecipeTestApi.step_data objects to append to |
| the output of this function. |
| status: One of 'success' (default), 'failure', or 'infra_failure'. The |
| result of the test case will be required to match this. |
| |
| Returns: |
| TestData object. |
| """ |
| properties = properties or {} |
| |
| # Tests shouldn't try to create their own tryjob environment, in the same way |
| # that cr-buildbucket builders shouldn't specify tryjob-related properties. |
| if "tryjob" in properties: |
| raise ValueError( |
| 'Test "%s": Do not specify a "tryjob" property; ' |
| "use the tryjob arg." % name |
| ) # pragma: no cover |
| |
| project = properties.get("project", "fuchsia") |
| |
| if clear_default_properties: |
| final_properties = {} |
| else: |
| final_properties = dict( |
| manifest="manifest/minimal", |
| remote="https://fuchsia.googlesource.com/integration", |
| project="integration", |
| target="x64", |
| packages=["//bundles/buildbot:core"], |
| ) |
| if "buildbucket" in properties: |
| # Re-evaluate this restriction if a test really needs to specify its |
| # own buildbucket properties. |
| raise ValueError( |
| 'Test "%s": Do not specify a "buildbucket" property; ' |
| "the test API should provide it." % name |
| ) # pragma: no cover |
| |
| if not tryjob: |
| final_properties["gcs_bucket"] = FuchsiaTestApi.DEFAULT_GCS_BUCKET |
| |
| # Provided properties override the defaults. |
| final_properties.update(properties) |
| |
| # Assemble the return value. |
| ret = self.m.status_check.test(name, status=status) |
| |
| ret += self.m.properties(**final_properties) |
| |
| # Add buildbucket properties |
| git_repo = "https://fuchsia.googlesource.com/" + project |
| if tryjob: |
| bb_build = self.m.buildbucket.try_build_message( |
| project=project, git_repo=git_repo |
| ) |
| else: |
| bb_build = self.m.buildbucket.ci_build_message( |
| project=project, git_repo=git_repo |
| ) |
| ret += self.m.buildbucket.build(bb_build) |
| |
| for s in steps: |
| ret += s |
| return ret |