blob: 45d3cbf7dc78ead29da3927dcc1705f3111eea11 [file] [edit]
# Copyright 2026 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.
"""Full test of abandon_old_changes module."""
from __future__ import annotations
from collections.abc import Iterator
from google.protobuf import json_format
from recipe_engine import post_process, recipe_api, recipe_test_api
from PB.go.chromium.org.luci.buildbucket.proto import common as common_pb
from RECIPE_MODULES.recipe_engine.buildbucket.api import Inherit
DEPS = [
'fuchsia/buildbucket_util',
'pigweed/trigger',
'recipe_engine/buildbucket',
'recipe_engine/step',
]
def RunSteps(api: recipe_api.RecipeScriptApi):
change = api.trigger.Change(
remote='https://pigweed.googlesource.com/pigweed/pigweed',
branch='main',
ref='3' * 40,
)
def commit_string(value: common_pb.GitilesCommit | Inherit | None):
if isinstance(value, common_pb.GitilesCommit):
return f'gitiles_commit: {json_format.MessageToDict(value)}'
if isinstance(value, Inherit):
return 'INHERIT'
return 'None' # pragma: no cover
commit = api.trigger.gitiles_commit(
change, verbose=True, prefer_inherit=False
)
pres = api.step.empty('prefer inherit false').presentation
pres.step_summary_text = commit_string(commit)
commit = api.trigger.gitiles_commit(
change, verbose=True, prefer_inherit=True
)
pres = api.step.empty('prefer inherit true').presentation
pres.step_summary_text = commit_string(commit)
def GenTests(api) -> Iterator[recipe_test_api.TestData]:
def contains(step: str, *values: str) -> recipe_test_api.TestData:
return api.post_check(post_process.StepSummaryContains, step, values)
yield api.buildbucket_util.test(
'ci',
contains(
'prefer inherit false', 'gitiles_commit', 'fuchsia', '2d72510e'
),
contains('prefer inherit true', 'INHERIT'),
api.post_process(post_process.DropExpectation),
)
yield api.buildbucket_util.test(
'try',
contains('prefer inherit false', 'gitiles_commit', '3' * 40),
contains('prefer inherit true', 'gitiles_commit', '3' * 40),
api.post_process(post_process.DropExpectation),
tryjob=True,
)
yield api.buildbucket_util.test(
'generic',
contains('prefer inherit false', 'gitiles_commit'),
contains('prefer inherit true', 'gitiles_commit'),
api.post_process(post_process.DropExpectation),
generic=True,
)