blob: b7633ad4b156695f2278b3f5e8eada127fec7991 [file] [log] [blame]
# 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
from .api import Shard
class TestsharderTestApi(recipe_test_api.RecipeTestApi):
def shard(self, tests=("hello", "goodbye"), **kwargs):
"""Creates a Shard object representing a shard."""
# The actual shard test schema has more fields than just "name", but
# recipes don't care about any of those fields, so we just use the bare
# minimum necessary to be somewhat realistic.
kwargs["tests"] = [{"name": test_name} for test_name in tests]
kwargs.setdefault("timeout_secs", 30 * 60)
return Shard(**kwargs)
def execute(self, step_name, shards):
"""Mocks the result from a call to execute.
Args:
step_name (str): The name of the step to mock.
shards (seq[Shard]): A sequence of Shard objects that will be mocked in
as the result for an execute call.
"""
return self.step_data(
step_name,
self.m.json.output([self._shard_to_dict(shard) for shard in shards]),
)
def _shard_to_dict(self, shard):
"""Returns a JSON-compatible dict representing the Shard.
The format follows the format os testsharder.Shard found here:
https://fuchsia.googlesource.com/fuchsia/+/main/tools/integration/testsharder/shard.go
"""
env = {"dimensions": shard.dimensions}
if shard.service_account:
env["service_account"] = shard.service_account
if shard.netboot:
env["netboot"] = shard.netboot
return {
"name": shard.name,
"tests": shard.tests,
"environment": env,
"deps": shard.deps,
"timeout_secs": shard.timeout_secs,
"summary": shard.summary,
}