blob: a31a8a3d3a0790c772f2693dbcec10074bb06025 [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 = [
"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],
)
if not rolls:
with api.step.nest('nothing to roll, exiting'):
return
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)
def commit_data(name, **kwargs):
return api.roll_util.commit_data(
name,
api.roll_util.commit('a' * 40, 'foo\nbar\n\nChange-Id: I1111'),
**kwargs,
)
yield api.test(
'success',
properties(api.bazel_roll.git_repo()),
api.roll_util.properties(commit_divider='--divider--'),
trigger('pigweed/pigweed'),
api.roll_util.forward_roll(),
commit_data('pigweed', prefix=''),
)
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, '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(
'name-not-found',
properties(api.bazel_roll.git_repo(remote=_url('third/repo'))),
trigger('third/repo'),
api.roll_util.forward_roll(),
api.post_process(post_process.MustRunRE, r'could not find name.*'),
api.post_process(post_process.DropExpectation),
status='FAILURE',
)
yield api.test(
'no-trigger',
properties(api.bazel_roll.git_repo()),
api.roll_util.forward_roll(),
commit_data('pigweed', prefix=''),
)
yield api.test(
'backwards',
properties(api.bazel_roll.git_repo()),
api.roll_util.backward_roll(),
)