# 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.submodule_roll.tests.full import InputProperties

DEPS = [
    "pigweed/checkout",
    "pigweed/roll_util",
    "pigweed/submodule_roll",
    "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()

    rolls = api.submodule_roll.update(checkout, props.submodule)

    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 properties(*submodules, **kwargs):
        props = InputProperties(**kwargs)
        assert len(submodules) == 1
        props.submodule.CopyFrom(submodules[0])
        return api.properties(props)

    yield api.test(
        'success',
        properties(*api.submodule_roll.submodules('a1')),
        api.submodule_roll.commit_data('a1', prefix=''),
        api.submodule_roll.gitmodules(a1='sso://foo/a1', b2='sso://foo/b2'),
        api.roll_util.forward_roll('a1'),
    )

    yield api.test(
        'noop',
        properties(*api.submodule_roll.submodules({'path': 'b2'})),
        api.submodule_roll.gitmodules(b2='b2', b2_branch='branch'),
        api.roll_util.noop_roll('b2'),
    )

    yield api.test(
        'missing',
        properties(*api.submodule_roll.submodules('b2')),
        api.submodule_roll.gitmodules(a1='sso://foo/a1'),
        status='FAILURE',
    )
