| # Copyright 2025 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. |
| """Test of gcs_upload module.""" |
| |
| from __future__ import annotations |
| |
| from collections.abc import Iterator |
| |
| from recipe_engine import post_process, recipe_api, recipe_test_api |
| |
| from PB.recipe_engine import result as result_pb |
| |
| DEPS = [ |
| 'pigweed/gcs_upload', |
| 'recipe_engine/path', |
| ] |
| |
| |
| def RunSteps(api: recipe_api.RecipeApi) -> result_pb.RawResult | None: |
| with api.gcs_upload(gcs_bucket='bucket') as gcs: |
| foo_json = api.path.start_dir / 'foo.json' |
| api.path.mock_add_file(foo_json) |
| gcs.upload(foo_json, 'foo.json') |
| |
| baz_dir = api.path.start_dir / 'baz' |
| api.path.mock_add_file(baz_dir / 'a') |
| api.path.mock_add_file(baz_dir / 'b') |
| api.path.mock_add_file(baz_dir / 'c') |
| gcs.upload(baz_dir, 'baz') |
| |
| with api.gcs_upload(parent=gcs, subdirectory='subdirectory') as sub: |
| bar_yaml = api.path.start_dir / 'bar.yaml' |
| api.path.mock_add_file(bar_yaml) |
| sub.upload(bar_yaml, 'bar.yaml') |
| |
| gcs.set_output_properties() |
| |
| return gcs.raw_result() |
| |
| |
| def GenTests(api) -> Iterator[recipe_test_api.TestData]: |
| yield api.test('basic', api.post_process(post_process.DropExpectation)) |