blob: 968f7951ddde345563a33e23c1515e6498247ca8 [file] [log] [blame]
# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
from __future__ import annotations
from PB.recipe_modules.pigweed.bazel_roll.tests.full import InputProperties
from recipe_engine import post_process
DEPS = [
"fuchsia/gitiles",
"fuchsia/roll_commit_message",
"pigweed/bazel_roll",
"pigweed/checkout",
"pigweed/roll_util",
"recipe_engine/properties",
"recipe_engine/step",
]
PROPERTIES = InputProperties
def RunSteps( # pylint: disable=invalid-name
api: recipe_api.RecipeScriptApi,
props: InputProperties,
):
checkout = api.checkout.fake_context()
assert len(props.git_repositories) == 1
rolls = api.bazel_roll.update_git_repository(
checkout=checkout,
git_repository=props.git_repositories[0],
)
pres = api.step.empty('commit message').presentation
pres.step_summary_text = api.roll_commit_message.format(
*rolls,
roll_prefix='roll:',
send_comment=True,
)
def GenTests(api) -> Generator[recipe_test_api.TestData, None, None]:
"""Create tests."""
def _url(x: str = 'pigweed/pigweed'):
assert ':' not in x
return f'https://pigweed.googlesource.com/{x}'
def trigger(url, **kwargs):
return api.checkout.ci_test_data(git_repo=_url(url), **kwargs)
def properties(repo: GitRepository, **kwargs):
props = InputProperties(**kwargs)
props.git_repositories.append(repo)
return api.properties(props)
yield api.test(
'success',
properties(api.bazel_roll.git_repo()),
api.roll_util.properties(commit_divider='--divider--'),
trigger('pigweed/pigweed'),
api.gitiles.log("pigweed.log pigweed", "A"),
)
yield api.test(
'unrecognized-remote',
properties(api.bazel_roll.git_repo(remote=_url('unrecognized-remote'))),
api.roll_util.properties(commit_divider='--divider--'),
trigger('unrecognized-remote'),
api.post_process(
post_process.MustRun,
'unrecognized-remote.failed to update commit hash',
),
status='FAILURE',
)
yield api.test(
'bad-trigger',
properties(
api.bazel_roll.git_repo(
remote=_url('foo'),
workspace_path='bar/WORKSPACE',
),
),
trigger('bar'),
status='FAILURE',
)
yield api.test(
'no-trigger',
properties(api.bazel_roll.git_repo()),
api.gitiles.log("pigweed.log pigweed", "A"),
)
yield api.test(
'backwards',
properties(api.bazel_roll.git_repo()),
api.gitiles.log("pigweed.log pigweed", "A", n=0),
)