# Copyright 2022 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 pipeline module."""

from recipe_engine import post_process

DEPS = [
    'pigweed/pipeline',
    'recipe_engine/step',
]


def RunSteps(api):
    if not api.pipeline.in_pipeline:
        api.step('not in pipeline', None)
        return

    api.step('in pipeline', None)

    api.step(f'round {api.pipeline.round}', None)

    prev_builds = api.pipeline.builds_from_previous_iteration
    api.step(f'{len(prev_builds)} previous builds', None)
    for build in prev_builds:
        api.step(f'previous build {build}', None)


def GenTests(api):  # pylint: disable=invalid-name
    def ran(x):
        return api.post_process(post_process.MustRun, x)

    yield api.test('nopipeline') + ran('not in pipeline')

    yield (
        api.test('round_0')
        + api.pipeline.props(0, [])
        + ran('in pipeline')
        + ran('round 0')
        + ran('0 previous builds')
    )

    yield (
        api.test('round_1')
        + api.pipeline.props(1, [123])
        + ran('in pipeline')
        + ran('round 1')
        + ran('1 previous builds')
        + ran('previous build 123')
    )

    yield (
        api.test('round_4')
        + api.pipeline.props(4, [123, 456, 789])
        + ran('in pipeline')
        + ran('round 4')
        + ran('3 previous builds')
        + ran('previous build 123')
        + ran('previous build 456')
        + ran('previous build 789')
    )

    yield api.test('empty')
