# 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 non-repo non-submodule functionality of checkout module."""

from PB.go.chromium.org.luci.scheduler.api.scheduler.v1 import (
    triggers as triggers_pb2,
)
from PB.recipe_modules.pigweed.checkout.tests.properties import InputProperties

DEPS = [
    'pigweed/checkout',
    'recipe_engine/json',
    'recipe_engine/properties',
    'recipe_engine/scheduler',
    'recipe_engine/step',
]

PROPERTIES = InputProperties


def RunSteps(api, props):  # pylint: disable=invalid-name
    checkout = api.checkout(props.checkout_options)

    def steplog(name, value):  # pylint: disable=invalid-name
        with api.step.nest(name) as pres:
            pres.step_summary_text = repr(value)

    # These lines are needed for coverage.
    steplog('revision', checkout.revision())
    steplog('revision', checkout.revision())  # Intentional repeat (caching).
    steplog('gerrit_host', checkout.gerrit_host())
    steplog('gerrit_project', checkout.gerrit_project())
    steplog('submodules', checkout.submodules())


def GenTests(api):  # pylint: disable=invalid-name
    def properties(**kwargs):
        kwargs.setdefault('remote', api.checkout.pigweed_repo)
        kwargs.setdefault('branch', None)
        props = InputProperties(
            checkout_options=api.checkout.git_options(**kwargs)
        )
        return api.properties(props)

    yield api.test('ci') + properties() + api.checkout.ci_test_data()

    yield (
        api.test('trigger')
        + properties()
        + api.checkout.ci_test_data()
        + api.scheduler(
            triggers=[
                triggers_pb2.Trigger(
                    gitiles=triggers_pb2.GitilesTrigger(
                        repo='https://pigweed.googlesource.com/pigweed/pigweed',
                        revision='2d72510e447ab60a9728aeea2362d8be2cbd7789',
                        ref='refs/heads/overridden-by-trigger',
                    ),
                ),
            ],
        )
    )

    yield (
        api.test('try')
        + properties(root_subdirectory='foo')
        + api.checkout.try_test_data()
        + api.checkout.cl_branch_parents(num_parents=2)
    )

    yield api.test('other') + properties()

    yield (
        api.test('not_in_gerrit')
        + properties()
        + api.step_data(
            'checkout pigweed.change data.number', api.json.output({}),
        )
    )
