|
| 1 | +// Copyright 2025 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 | +// https://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 | +using Google.Apis.Storage.v1.Data; |
| 16 | +using System.Threading.Tasks; |
| 17 | +using Xunit; |
| 18 | + |
| 19 | +[Collection(nameof(StorageFixture))] |
| 20 | +public class ListSoftDeleteBucketsTest |
| 21 | +{ |
| 22 | + private readonly StorageFixture _fixture; |
| 23 | + |
| 24 | + public ListSoftDeleteBucketsTest(StorageFixture fixture) |
| 25 | + { |
| 26 | + _fixture = fixture; |
| 27 | + } |
| 28 | + |
| 29 | + [Fact] |
| 30 | + public async Task ListSoftDeleteBuckets() |
| 31 | + { |
| 32 | + ListSoftDeletedBucketsSample listSoftDeletedBucketsSample = new ListSoftDeletedBucketsSample(); |
| 33 | + var bucketName = _fixture.GenerateBucketName(); |
| 34 | + var softDeleteBucket = _fixture.CreateBucket(bucketName, multiVersion: false, softDelete: true, registerForDeletion: true); |
| 35 | + await _fixture.Client.DeleteBucketAsync(softDeleteBucket.Name); |
| 36 | + |
| 37 | + var actualBuckets = listSoftDeletedBucketsSample.ListSoftDeletedBuckets(_fixture.ProjectId); |
| 38 | + // Check the list contains the bucket we just soft-deleted. |
| 39 | + Assert.Contains(actualBuckets, bucket => bucket.Name == softDeleteBucket.Name && bucket.Generation == softDeleteBucket.Generation); |
| 40 | + // Check all the buckets in the list are soft-deleted buckets. |
| 41 | + Assert.All(actualBuckets, AssertSoftDeletedBucket); |
| 42 | + } |
| 43 | + |
| 44 | + // Validates that the given bucket is soft-deleted. |
| 45 | + private void AssertSoftDeletedBucket(Bucket b) |
| 46 | + { |
| 47 | + Assert.NotNull(b.Generation); |
| 48 | + Assert.NotNull(b.HardDeleteTimeDateTimeOffset); |
| 49 | + Assert.NotNull(b.SoftDeleteTimeDateTimeOffset); |
| 50 | + } |
| 51 | +} |
0 commit comments