| # 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. |
| """Full test of bazel_roll module's update_value() method.""" |
| |
| from __future__ import annotations |
| |
| from collections.abc import Iterator |
| |
| from recipe_engine import post_process, recipe_api, recipe_test_api |
| |
| from PB.recipe_modules.pigweed.module_bazel_lock_roll.tests.update import ( |
| UpdateProperties, |
| ) |
| |
| DEPS = [ |
| 'pigweed/checkout', |
| 'pigweed/module_bazel_lock_roll', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| ] |
| |
| INLINE_PROPERTIES_PROTO = """ |
| import "recipe_modules/pigweed/module_bazel_lock_roll/module_bazel_lock.proto"; |
| |
| message UpdateProperties { |
| repeated recipe_modules.pigweed.module_bazel_lock_roll.ModuleBazelLock module_bazel_roll_entries = 1; |
| } |
| """ |
| |
| PROPERTIES = UpdateProperties |
| |
| |
| def RunSteps(api: recipe_api.RecipeScriptApi, props: UpdateProperties): |
| checkout = api.checkout.fake_context() |
| |
| assert props.module_bazel_roll_entries |
| rolls = api.module_bazel_lock_roll.update( |
| checkout, |
| props.module_bazel_roll_entries[0], |
| ) |
| |
| if not rolls: |
| return |
| |
| with api.step.nest('roll') as pres: |
| assert len(rolls) == 1 |
| roll = rolls[0] |
| |
| pres.properties['roll'] = roll.output_property() |
| pres.step_summary_text = roll.message_header() |
| |
| msg = api.step.empty('commit message').presentation |
| msg.step_summary_text = roll.message_body() |
| |
| |
| def GenTests(api) -> Iterator[recipe_test_api.TestData]: |
| def properties(**kwargs): |
| props = UpdateProperties() |
| props.module_bazel_roll_entries.append( |
| api.module_bazel_lock_roll.entry(**kwargs), |
| ) |
| return api.properties(props) |
| |
| yield api.test( |
| 'update', |
| properties(subdirectory='foo'), |
| api.step_data('MODULE.bazel.lock.git diff', retcode=1), |
| api.post_check(post_process.MustRun, 'roll'), |
| ) |
| |
| yield api.test( |
| 'noop-bazel', |
| properties(bazel_executable='bazel-3'), |
| api.step_data('MODULE.bazel.lock.git diff', retcode=0), |
| api.post_check( |
| post_process.MustRun, |
| 'MODULE.bazel.lock.bazel-3 mod deps --lockfile_mode=update', |
| ), |
| api.post_check( |
| post_process.StepCommandContains, |
| 'MODULE.bazel.lock.bazel-3 mod deps --lockfile_mode=update', |
| ['bazel-3'], |
| ), |
| api.post_check(post_process.DoesNotRun, 'roll'), |
| ) |