blob: bfb13df4d2fb7e9aa7cb0e307745ad238ad3a7a1 [file] [log] [blame]
# Copyright 2019 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 FuchsiaTestingRequestsTestApi(recipe_test_api.RecipeTestApi):
EXAMPLE_TESTS_JSON = [
{
'test': {
'name': 'hello',
'label': '//a/b/c:hello_test(//toolchain)',
'os': 'fuchsia',
'path': '/path/to/hello',
'package_url': 'fuchsia-pkg://fuchsia.com/hello',
}
},
{
'test': {
'name': 'goodbye',
'label': '//a/b/c:goodbye_test(//toolchain)',
'os': 'fuchsia',
'path': '/path/to/goodbye',
'package_url': 'fuchsia-pkg://fuchsia.com/goodbye',
}
},
]
def default_tests(self):
"""Returns mock step data for the output of testsharder.
Returns:
list(testsharder.Test)
"""
return [
self.m.testsharder.test(**t['test']) for t in self.EXAMPLE_TESTS_JSON
]
def task_request_jsonish(self, legacy_qemu):
ret = self.m.swarming.example_task_request_jsonish()
ret['tags'] = ['uses_legacy_qemu:%s' % str(legacy_qemu).lower()]
return ret
def task_requests_step_data(self, task_requests, step_name):
"""Returns mock step data for swarming task requests.
This should be used by any test which calls api.testing_requests.shard_requests() and expects
to shard tests.
Args:
shards (seq[dict]): A set of example shards which should
be used as step data for the result of invoking the testsharder.
step_name (str): name to use for step data
Returns:
RecipeTestApi.step_data for the extract_results step.
"""
return self.step_data(step_name, self.m.json.output(task_requests))
def shards_step_data(self,
shards,
step_name='download build artifacts.load test shards'):
"""Returns mock step data for test shards.
This should be used by any test which calls api.fuchsia.test*() and expects
to shard tests.
Args:
shards (seq[api.testsharder.Shard]): A set of example shards which should
be used as step data for the result of invoking the testsharder.
step_name (str): name to use for step data
Returns:
RecipeTestApi.step_data for the extract_results step.
"""
return self.m.testsharder.execute(step_name=step_name, shards=shards)
def secrets_step_data(self):
"""Returns mock step data for the secrets pipeline.
This should be used by any test which calls api.fuchsia.test() with
requires_secrets is set to True.
Returns:
list(RecipeTestApi.step_data) for the steps around secrets decryption.
"""
secret_name = 'auth-token'
step_data = self.step_data(
'process secret specs.list',
self.m.file.listdir([
'%s.json' % secret_name,
'ciphertext' # the 'ciphertext' subdir, which will be skipped.
]))
step_data += self.step_data(
'process secret specs.read spec for %s' % secret_name,
self.m.json.output({
'cloudkms_key_path': 'key-path',
}))
step_data += self.step_data(
'process secret specs.decrypt secret for %s' % secret_name,
self.m.raw_io.output_text('plaintext'))
return step_data
def args_test_data(self, target='x64', variants=None):
args = self.m.json.output({
'board': 'boards/x64.gni',
'build_type': 'release',
'product': 'products/core.gni',
'target': target,
'variants': variants if variants else [],
})
return self.step_data('download build artifacts.read args.json', args)