| # Copyright 2020 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 submodule functionality of checkout module.""" |
| |
| from __future__ import annotations |
| |
| from typing import Generator |
| |
| from PB.recipe_modules.pigweed.checkout.tests.properties import InputProperties |
| from recipe_engine import recipe_test_api |
| |
| DEPS = [ |
| 'pigweed/checkout', |
| 'pigweed/cq_deps', |
| 'recipe_engine/path', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| |
| def RunSteps(api, props): # pylint: disable=invalid-name |
| checkout = api.checkout(props.checkout_options) |
| |
| with api.step.nest('snapshot_to_dir'): |
| checkout.snapshot_to_dir(api.path.start_dir / 'snapshot') |
| |
| |
| def GenTests(api) -> Generator[recipe_test_api.TestData, None, None]: |
| def properties(**kwargs): |
| kwargs.setdefault('initialize_submodules', False) |
| kwargs.setdefault('remote', api.checkout.pigweed_repo_dot_git) |
| kwargs.setdefault('branch', None) |
| props = InputProperties( |
| checkout_options=api.checkout.git_options(**kwargs) |
| ) |
| return api.properties(props) |
| |
| submodule_data = api.checkout.submodules( |
| api.checkout.submodule('foo', 'https://x.googlesource.com/foo', '-'), |
| api.checkout.submodule('bar', 'https://x.googlesource.com/bar', '+'), |
| api.checkout.submodule('baz', 'https://x.googlesource.com/baz.git'), |
| # Using 'b/c/d' instead of 'a/b/c' because an 'a/' prefix is treated |
| # specially by Gerrit and the buildbucket module. |
| api.checkout.submodule( |
| 'b/c/d', 'https://x.googlesource.com/b/c/d', ' ' |
| ), |
| ) |
| |
| yield ( |
| api.test('submodule-try') |
| + properties() |
| + api.checkout.try_test_data(git_repo='https://x.googlesource.com/baz') |
| + submodule_data |
| + api.checkout.all_changes_applied() |
| ) |
| |
| yield ( |
| api.test('submodule-ci') |
| + properties() |
| + api.checkout.ci_test_data(git_repo='https://x.googlesource.com/baz') |
| + submodule_data |
| ) |
| |
| yield ( |
| api.test('submodule-not-initialized', status='INFRA_FAILURE') |
| + properties() |
| + api.checkout.ci_test_data(git_repo='https://x.googlesource.com/b/c/d') |
| + submodule_data |
| ) |
| |
| yield ( |
| api.test('submodule-try-not-found', status='INFRA_FAILURE') |
| + properties() |
| + api.checkout.try_test_data(git_repo='https://x.googlesource.com/xyz') |
| + submodule_data |
| + api.checkout.no_changes_applied() |
| ) |
| |
| yield ( |
| api.test('submodule-try-equivalent') |
| + properties( |
| equivalent_remotes=( |
| ( |
| 'https://z.googlesource.com/foo', |
| 'https://x.googlesource.com/foo', |
| ), |
| ), |
| ) |
| + api.checkout.try_test_data(git_repo='https://z.googlesource.com/foo') |
| + submodule_data |
| + api.checkout.all_changes_applied() |
| ) |
| |
| def cl(project, change, patchset=1, name='pigweed'): |
| return api.checkout.cl( |
| host=f'{name}-review.googlesource.com', |
| project=project, |
| change=change, |
| patchset=patchset, |
| ) |
| |
| yield ( |
| api.test('submodule-try-multiple') |
| + properties() |
| + api.checkout.try_test_data( |
| gerrit_changes=[ |
| cl('foo', 1234, name='x'), |
| cl('bar', 2345, name='x'), |
| cl('pigweed/pigweed', 3456), |
| ] |
| ) |
| + submodule_data |
| + api.checkout.all_changes_applied() |
| + api.checkout.change_applied('x:1234') |
| + api.checkout.change_applied('x:2345') |
| + api.checkout.change_applied('pigweed:3456') |
| ) |
| |
| yield ( |
| api.test('submodule-try-multiple-one-missing') |
| + properties() |
| + api.checkout.try_test_data( |
| gerrit_changes=[ |
| cl('foo', 1234, name='x'), |
| cl('not-a-submodule', 2345, name='x'), |
| cl('pigweed/pigweed', 3456), |
| ] |
| ) |
| + submodule_data |
| + api.checkout.some_changes_applied() |
| + api.checkout.change_applied('x:1234') |
| + api.checkout.change_not_applied('x:2345') |
| + api.checkout.change_applied('pigweed:3456') |
| ) |
| |
| # These tests are nominally identical to 'submodule-try-multiple' and |
| # 'submodule-try-multiple-one-missing' above but use the cq_deps module. |
| # After the 'process gerrit changes' step all changes are minor (e.g. |
| # '2345' instead of '2345L'). |
| yield ( |
| api.test('submodule-try-multiple-cqdeps') |
| + properties() |
| + api.checkout.try_test_data( |
| git_repo='https://x.googlesource.com/foo', |
| change_number=1234, |
| patch_set=1, |
| ) |
| + api.cq_deps.details( |
| 'x:1234', |
| patches_json=True, |
| prefix='checkout pigweed.change data.process gerrit changes.', |
| ) |
| + api.cq_deps.patches_json( |
| 'x:1234', |
| 'x:2345', |
| 'pigweed:3456', |
| prefix='checkout pigweed.change data.process gerrit changes.', |
| ) |
| + api.cq_deps.details( |
| 'x:2345', |
| project='bar', |
| prefix='checkout pigweed.change data.process gerrit changes.', |
| ) |
| + api.cq_deps.details( |
| 'pigweed:3456', |
| project='pigweed/pigweed', |
| prefix='checkout pigweed.change data.process gerrit changes.', |
| ) |
| + submodule_data |
| + api.checkout.all_changes_applied() |
| + api.checkout.change_applied('x:1234') |
| + api.checkout.change_applied('x:2345') |
| + api.checkout.change_applied('pigweed:3456') |
| ) |
| |
| yield ( |
| api.test('submodule-try-multiple-one-missing-one-forbidden-cqdeps') |
| + properties() |
| + api.checkout.try_test_data( |
| git_repo='https://x.googlesource.com/foo', |
| change_number=1234, |
| patch_set=1, |
| ) |
| + api.cq_deps.details( |
| 'x:1234', |
| patches_json=True, |
| prefix='checkout pigweed.change data.process gerrit changes.', |
| ) |
| + api.cq_deps.patches_json( |
| 'x:1234', |
| 'x:2345', |
| 'pigweed:3456', |
| 'forbidden:9999', |
| prefix='checkout pigweed.change data.process gerrit changes.', |
| ) |
| + api.cq_deps.details( |
| 'x:2345', |
| project='not-a-submodule', |
| prefix='checkout pigweed.change data.process gerrit changes.', |
| ) |
| + api.cq_deps.details( |
| 'pigweed:3456', |
| project='pigweed/pigweed', |
| prefix='checkout pigweed.change data.process gerrit changes.', |
| ) |
| + api.cq_deps.forbidden( |
| 'forbidden:9999', |
| prefix='checkout pigweed.change data.process gerrit changes.', |
| ) |
| + submodule_data |
| + api.checkout.some_changes_applied() |
| + api.checkout.change_applied('x:1234') |
| + api.checkout.change_not_applied('x:2345') |
| + api.checkout.change_not_applied('forbidden:9999') |
| + api.checkout.change_applied('pigweed:3456') |
| ) |
| |
| yield ( |
| api.test('submodule-try-included-excluded', status='INFRA_FAILURE') |
| + properties(included_submodules=['foo'], excluded_submodules=['bar']) |
| + api.checkout.ci_test_data() |
| ) |
| |
| yield ( |
| api.test('submodule-try-included') |
| + properties(included_submodules=['nanopb']) |
| + api.checkout.ci_test_data() |
| + api.checkout.included_submodule('nanopb') |
| ) |
| |
| yield ( |
| api.test('submodule-try-excluded') |
| + properties(excluded_submodules=['nanopb']) |
| + api.checkout.ci_test_data() |
| + api.checkout.excluded_submodule('nanopb') |
| ) |
| |
| yield ( |
| api.test('submodule-try-excluded-missing', status='INFRA_FAILURE') |
| + properties(excluded_submodules=['missing']) |
| + api.checkout.ci_test_data() |
| ) |
| |
| yield ( |
| api.test('submodule-repeated-nomatch', status='FAILURE') |
| + properties() |
| + api.checkout.try_test_data('https://x.googlesource.com/foo') |
| + api.checkout.submodules( |
| api.checkout.submodule( |
| 'foo1', |
| 'https://x.googlesource.com/foo', |
| branch='release', |
| ), |
| api.checkout.submodule( |
| 'foo2', |
| 'https://x.googlesource.com/foo', |
| branch='dev', |
| ), |
| ) |
| ) |
| |
| yield ( |
| api.test('submodule-repeated-match') |
| + properties() |
| + api.checkout.try_test_data('https://x.googlesource.com/foo') |
| + api.checkout.submodules( |
| api.checkout.submodule( |
| 'foo1', |
| 'https://x.googlesource.com/foo', |
| branch='main', |
| ), |
| api.checkout.submodule( |
| 'foo2', |
| 'https://x.googlesource.com/foo', |
| branch='dev', |
| ), |
| ) |
| ) |
| |
| yield ( |
| api.test('submodule-repeated-twomatch', status='FAILURE') |
| + properties() |
| + api.checkout.try_test_data('https://x.googlesource.com/foo') |
| + api.checkout.submodules( |
| api.checkout.submodule( |
| 'foo1', |
| 'https://x.googlesource.com/foo', |
| branch='main', |
| ), |
| api.checkout.submodule( |
| 'foo2', |
| 'https://x.googlesource.com/foo', |
| branch='main', |
| ), |
| ) |
| ) |
| |
| yield ( |
| api.test('insteadof') |
| + properties( |
| rewrites=[('https://github.com/foo', 'https://github.mirror/foo')], |
| ) |
| + api.checkout.try_test_data() |
| + api.checkout.submodules( |
| api.checkout.submodule('foobar', 'https://github.com/foo/bar', ' '), |
| ) |
| + api.checkout.all_changes_applied() |
| ) |