blob: 55a32cb7484ce8675e6aa8d5e69df3a1dbbd8074 [file] [log] [blame] [edit]
# Copyright 2025 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 collections.abc import Iterator
from recipe_engine import recipe_api, recipe_test_api
from PB.recipe_modules.pigweed.variable_roll.tests.cipd import (
CipdInputProperties,
)
from PB.recipe_modules.pigweed.variable_roll.variable_entry import (
CipdVariableEntry,
)
DEPS = [
'fuchsia/roll_commit_message',
'pigweed/checkout',
'pigweed/cipd_roll',
'pigweed/variable_roll',
'recipe_engine/properties',
'recipe_engine/step',
]
PROPERTIES = CipdInputProperties
_TEST_DATA = f"""
BAR = 'git_revision:{'1' * 40}'
# ROLL: Comment
FOO = "git_revision:{'0' * 40}"
BAZ = "git_revision:{'2' * 40}"
"""
def RunSteps( # pylint: disable=invalid-name
api: recipe_api.RecipeScriptApi,
props: CipdInputProperties,
):
checkout = api.checkout.fake_context()
assert len(props.cipd_entries) == 1
rolls = api.variable_roll.update_cipd(
checkout=checkout,
variable_entry=props.cipd_entries[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) -> Iterator[recipe_test_api.TestData]:
"""Create tests."""
def properties(pkg: CipdVariableEntry, **kwargs):
props = CipdInputProperties(**kwargs)
props.cipd_entries.append(pkg)
return api.properties(props)
yield api.test(
'success',
properties(
api.variable_roll.cipd_entry(
path='MODULE.bazel',
spec='fuchsia/third_party/rust/${platform}',
variable='FOO',
ref='latest',
tag='git_revision',
),
),
api.cipd_roll.multiple_common_tags(
'MODULE.bazel[FOO]',
[
'fuchsia/third_party/rust/mac-amd64',
'fuchsia/third_party/rust/mac-arm64',
'fuchsia/third_party/rust/linux-amd64',
],
),
api.variable_roll.cipd_read(
'MODULE.bazel[FOO]',
_TEST_DATA,
needs_update=True,
),
)