| # 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 cipd_upload module.""" |
| |
| from __future__ import annotations |
| |
| from collections.abc import Iterator |
| |
| from recipe_engine import recipe_api, recipe_test_api |
| |
| from PB.recipe_modules.pigweed.cipd_upload.tests.full import InputProperties |
| |
| DEPS = [ |
| 'pigweed/cipd_upload', |
| 'recipe_engine/path', |
| 'recipe_engine/platform', |
| 'recipe_engine/properties', |
| ] |
| |
| INLINE_PROPERTIES_PROTO = """ |
| message InputProperties { |
| bool do_not_add_platform = 1; |
| repeated string package_paths = 2; |
| string package_root = 3; |
| string path = 4; |
| string repository = 5; |
| string search_tag_key = 6; |
| string search_tag_value = 7; |
| } |
| """ |
| |
| PROPERTIES = InputProperties |
| |
| |
| def RunSteps(api: recipe_api.RecipeScriptApi, props: InputProperties): |
| """Run test steps.""" |
| |
| add_platform = not props.do_not_add_platform |
| props.path = props.path or 'foo/bar/baz' |
| props.repository = ( |
| props.repository or 'https://pigweed.googlesource.com/pigweed/pigweed' |
| ) |
| props.search_tag_key = props.search_tag_key or 'key' |
| props.search_tag_value = props.search_tag_value or 'value' |
| |
| package_root = api.path.start_dir / (props.package_root or 'pkgroot') |
| |
| metadata = [('abc', '123')] |
| |
| api.cipd_upload( |
| add_platform=add_platform, |
| metadata=metadata, |
| paths=props.package_paths, |
| package_root=package_root, |
| cipd_path=props.path, |
| repository=props.repository, |
| search_tag={props.search_tag_key: props.search_tag_value}, |
| ) |
| |
| |
| def GenTests(api) -> Iterator[recipe_test_api.TestData]: |
| """Define tests.""" |
| |
| yield api.test( |
| 'found', |
| api.platform('linux', 64), |
| api.cipd_upload.search_results('foo/bar/baz key:value', instances=1), |
| ) |
| |
| yield api.test( |
| 'upload', |
| api.platform('linux', 64), |
| api.cipd_upload.search_results('foo/bar/baz key:value', instances=0), |
| ) |
| |
| yield api.test( |
| 'extra_tags', |
| api.properties(extra_tags={'abc': '123'}), |
| api.platform('linux', 64), |
| api.cipd_upload.search_results('foo/bar/baz key:value', instances=0), |
| ) |