| OLD | NEW |
| (Empty) |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import hashlib | |
| 6 import os | |
| 7 import struct | |
| 8 import sys | |
| 9 from recipe_engine import recipe_test_api | |
| 10 | |
| 11 | |
| 12 class BotUpdateTestApi(recipe_test_api.RecipeTestApi): | |
| 13 def output_json(self, root, first_sln, revision_mapping, git_mode, | |
| 14 force=False, fail_patch=False, output_manifest=False, | |
| 15 fixed_revisions=None): | |
| 16 """Deterministically synthesize json.output test data for gclient's | |
| 17 --output-json option. | |
| 18 """ | |
| 19 active = True | |
| 20 | |
| 21 output = { | |
| 22 'did_run': active, | |
| 23 'patch_failure': False | |
| 24 } | |
| 25 | |
| 26 # Add in extra json output if active. | |
| 27 if active: | |
| 28 properties = { | |
| 29 property_name: self.gen_revision(project_name, git_mode) | |
| 30 for project_name, property_name in revision_mapping.iteritems() | |
| 31 } | |
| 32 properties.update({ | |
| 33 '%s_cp' % property_name: ('refs/heads/master@{#%s}' % | |
| 34 self.gen_revision(project_name, False)) | |
| 35 for project_name, property_name in revision_mapping.iteritems() | |
| 36 }) | |
| 37 | |
| 38 output.update({ | |
| 39 'patch_root': root or first_sln, | |
| 40 'root': first_sln, | |
| 41 'properties': properties, | |
| 42 'step_text': 'Some step text' | |
| 43 }) | |
| 44 | |
| 45 if output_manifest: | |
| 46 output.update({ | |
| 47 'manifest': { | |
| 48 project_name: { | |
| 49 'repository': 'https://fake.org/%s.git' % project_name, | |
| 50 'revision': self.gen_revision(project_name, git_mode), | |
| 51 } | |
| 52 for project_name in revision_mapping | |
| 53 } | |
| 54 }) | |
| 55 | |
| 56 if fixed_revisions: | |
| 57 output['fixed_revisions'] = fixed_revisions | |
| 58 | |
| 59 if fail_patch: | |
| 60 output['log_lines'] = [('patch error', 'Patch failed to apply'),] | |
| 61 output['patch_failure'] = True | |
| 62 output['patch_apply_return_code'] = 1 | |
| 63 if fail_patch == 'download': | |
| 64 output['patch_apply_return_code'] = 3 | |
| 65 return self.m.json.output(output) | |
| 66 | |
| 67 @staticmethod | |
| 68 def gen_revision(project, GIT_MODE): | |
| 69 """Hash project to bogus deterministic revision values.""" | |
| 70 h = hashlib.sha1(project) | |
| 71 if GIT_MODE: | |
| 72 return h.hexdigest() | |
| 73 else: | |
| 74 return struct.unpack('!I', h.digest()[:4])[0] % 300000 | |
| OLD | NEW |