| # 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, |
| paths=(), |
| status='success'): |
| """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. |
| """ |
| 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 paths: |
| ret += self.m.path.exists(*paths) |
| |
| return ret |