blob: 51d022ca4df95173b65de5709ca661f6b8fc3d8b [file] [log] [blame]
# Copyright 2016 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 RECIPE_MODULES.fuchsia.jiri.api import JiriApi
class JiriTestApi(recipe_test_api.RecipeTestApi):
# Exposed for use in examples
EnsureFileVerificationError = JiriApi.EnsureFileVerificationError
NoSuchProjectError = JiriApi.NoSuchProjectError
RebaseError = JiriApi.RebaseError
def read_manifest_element(
self,
element_name,
test_output,
nesting=None,
step_name=None,
):
"""Mocks a call to JiriApi.read_manifest_element.
Args:
test_output (Dict): The data to use as JSON in the step's stdout response.
(See JiriApi for docs on remaining args)
Returns:
recipe_test_api.TestData simulating a step to read data from a manifest.
"""
# `manifest` and `element_type` are not used by this method. Including them
# as parameters is intentionally done for parity between this method's and
# JiriApi.read_manifest_element's signatures.
if not step_name:
step_name = "read manifest for %s" % element_name
if nesting:
step_name = "%s.%s" % (nesting, step_name) # pragma: no cover
step_output = self.m.json.output(test_output)
return self.step_data(step_name, stdout=step_output)
@property
def example_revision(self): # pragma: no cover
return "c22471f4e3f842ae18dd9adec82ed9eb78ed1127"
@property
def example_snapshot(self):
return """<manifest>
<projects>
<project name="manifest" path="manifest" remote="https://fuchsia.googlesource.com/manifest" revision="4c2b0da3c06341db5cebe4d02c78c93c3b2bd78b"/>
</projects>
</manifest>"""
@property
def example_snapshot_diff(self):
return {
"new_projects": [
{
"name": "new_project",
"path": "path/to/new_project",
"relative_path": ".",
"remote": "http://example.com",
"revision": "abc",
}
],
"deleted_projects": [
{
"name": "deleted_project",
"path": "path/to/deleted_project",
"relative_path": ".",
"remote": "http://example.com",
"revision": "def",
}
],
"updated_projects": [
{
"name": "updated_project",
"path": "path/to/updated_project",
"relative_path": ".",
"remote": "http://example.com",
"revision": "ghi",
"old_revision": "GHI",
"cls": [
{
"number": "123",
"url": "http://example.com/c/123",
"commit": "123_abc",
"subject": "hello",
}
],
}
],
}
@property
def example_source_manifest(self):
return {
"directories": {
"manifest": {
"git_checkout": {
"repo_url": "https://fuchsia.googlesource.com/manifest",
"revision": "4c2b0da3c06341db5cebe4d02c78c93c3b2bd78b",
}
}
}
}
def example_resolve_data(self, package):
"""Creates example data for jiri resolve subcommand.
Args:
package: A string with the package name to generate data for.
Returns:
A StepTestData with a multiline string in stdout. The multiline string
has the subdirectory package in one line and the package, platforms and
version in a second line.
"""
test_data = ["@Subdir %s" % package]
if package.endswith("${platform}"):
prefix = package[0 : package.index("/${platform}")]
platform_str = "%s/${platform=linux-amd64,mac-amd64} version:2.5.0" % (
prefix
)
test_data.append(platform_str)
else:
test_data.append("%s version:2.5.0" % package)
data = "\n".join(test_data)
return self.m.raw_io.output_text(data)
def example_edit(self, imports, projects, packages):
"""Creates example JSON output for the Jiri edit subcommand.
The data returned by this command is similar to the data generated when
`Jiri edit` is invoked with the -json-output flag.
Args:
imports (List(tuple)): A list of (name, revision) tuples representing
imports to update in the manifest.
projects (List(tuple)): A list of (name, revision) tuples representing
projects to update in the manifest.
packages (List(tuple)): A list of (name, version) tuples representing
packages to update in the manifest.
Returns:
A dict representing JSON that matches the output of the Jiri edit
subcommand. The dict has the following structure:
{
'imports': [
{
'name': ...
'remote': ...
'old_revision': ...
'new_revision': ...
},
...
],
'projects': [
{
'name': ...
'remote': ...
'path: ...
'old_revision': ...
'new_revision': ...
},
...
],
'packages': [
{
'name': ...
'old_version': ...
'new_version': ...
},
...
],
}
Where each entry in imports, projects and packages is a dict representing
an edit to an import, project and package, respectively.
"""
project_edits = []
for project in projects:
name, revision = project
project_edits.append(
{
"name": name,
"remote": "http://example.com",
"path": "/path/to/" + name,
"old_revision": "[OLD_REVISION]",
"new_revision": revision,
}
)
import_edits = []
for imp in imports:
name, revision = imp
import_edits.append(
{
"name": name,
"remote": "http://example.com",
"old_revision": "[OLD_REVISION]",
"new_revision": revision,
}
)
package_edits = []
for package in packages:
name, version = package
package_edits.append(
{"name": name, "old_version": "[OLD_VERSION]", "new_version": version}
)
return {
"projects": project_edits,
"imports": import_edits,
"packages": package_edits,
}
def project(self, projects):
"""Provides test mock for the `project` method."""
assert projects is not None
return self.m.json.output(projects)
def package(self, packages):
"""Provides test mock for the `package` method."""
assert packages is not None
return self.m.json.output(packages)
def snapshot(self, data):
"""Provides test mock for the `snapshot` method."""
assert data is not None
return self.m.raw_io.output_text(data, name="snapshot")
def snapshot_diff(self, data):
"""Provides test mock for the `snapshot_diff` method."""
assert data is not None
return self.m.json.output_stream(data, name="snapshot diff")
def source_manifest(self, data):
"""Provides test mock for the `source_manifest` method."""
assert data is not None
return self.m.json.output(data, name="source manifest")