|
| 1 | +# Copyright 2021 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import uuid |
| 16 | + |
| 17 | +from google.cloud import storage |
| 18 | +import pytest |
| 19 | + |
| 20 | +import storage_create_bucket_turbo_replication |
| 21 | +import storage_get_rpo |
| 22 | +import storage_set_rpo_async_turbo |
| 23 | +import storage_set_rpo_default |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture |
| 27 | +def dual_region_bucket(): |
| 28 | + """Yields a dual region bucket that is deleted after the test completes.""" |
| 29 | + bucket = None |
| 30 | + while bucket is None or bucket.exists(): |
| 31 | + bucket_name = "bucket-lock-{}".format(uuid.uuid4()) |
| 32 | + bucket = storage.Client().bucket(bucket_name) |
| 33 | + bucket.location = "NAM4" |
| 34 | + bucket.create() |
| 35 | + yield bucket |
| 36 | + bucket.delete(force=True) |
| 37 | + |
| 38 | + |
| 39 | +def test_get_rpo(dual_region_bucket, capsys): |
| 40 | + storage_get_rpo.get_rpo(dual_region_bucket.name) |
| 41 | + out, _ = capsys.readouterr() |
| 42 | + assert f"RPO for {dual_region_bucket.name} is DEFAULT." in out |
| 43 | + |
| 44 | + |
| 45 | +def test_set_rpo_async_turbo(dual_region_bucket, capsys): |
| 46 | + storage_set_rpo_async_turbo.set_rpo_async_turbo(dual_region_bucket.name) |
| 47 | + out, _ = capsys.readouterr() |
| 48 | + assert f"RPO is ASYNC_TURBO for {dual_region_bucket.name}." in out |
| 49 | + |
| 50 | + |
| 51 | +def test_set_rpo_default(dual_region_bucket, capsys): |
| 52 | + storage_set_rpo_default.set_rpo_default(dual_region_bucket.name) |
| 53 | + out, _ = capsys.readouterr() |
| 54 | + assert f"RPO is DEFAULT for {dual_region_bucket.name}." in out |
| 55 | + |
| 56 | + |
| 57 | +def test_create_bucket_turbo_replication(capsys): |
| 58 | + bucket_name = "test-rpo-{}".format(uuid.uuid4()) |
| 59 | + storage_create_bucket_turbo_replication.create_bucket_turbo_replication(bucket_name) |
| 60 | + out, _ = capsys.readouterr() |
| 61 | + assert f"{bucket_name} created with RPO ASYNC_TURBO in NAM4." in out |
0 commit comments