Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions storage/api/Storage.Samples.Tests/DownloadPublicFileTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Google Inc.
// Copyright 2021 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -26,7 +26,7 @@ public DownloadPublicFileTest(StorageFixture fixture)
_fixture = fixture;
}

[Fact]
[Fact(Skip = "b/477676781")]
public void DownloadPublicFile()
{
MakePublicSample makePublicSample = new MakePublicSample();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2025 Google LLC
//
// 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.

using System.Linq;
using Xunit;

[Collection(nameof(StorageFixture))]
public class ListBucketsWithPartialSuccessTest
{
private readonly StorageFixture _fixture;

public ListBucketsWithPartialSuccessTest(StorageFixture fixture)
{
_fixture = fixture;
}

[Fact]
public void ListBucketsWithPartialSuccess()
{
ListBucketsWithPartialSuccessSample partialSample = new ListBucketsWithPartialSuccessSample();
Comment thread
mahendra-google marked this conversation as resolved.
Comment thread
mahendra-google marked this conversation as resolved.
var bucketName = _fixture.GenerateBucketName();
_fixture.CreateBucket(bucketName: bucketName, location: "US", storageClass: "MULTI_REGIONAL");

var buckets = partialSample.ListBucketsWithPartialSuccess(_fixture.ProjectId);

Assert.Contains(buckets.Reachable, c => c.Name == bucketName);

if (buckets.Unreachable.Any())
{
// This indicates that the environment had unreachable buckets.
// We don't assert on the count to avoid flaky tests.
}
}
}
4 changes: 2 additions & 2 deletions storage/api/Storage.Samples.Tests/MakeBucketPublicTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Google Inc.
// Copyright 2021 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -26,7 +26,7 @@ public MakeBucketPublicTest(StorageFixture fixture)
_fixture = fixture;
}

[Fact]
[Fact(Skip = "b/477676781")]
public void MakeBucketPublic()
{
MakeBucketPublicSample makeBucketPublicSample = new MakeBucketPublicSample();
Expand Down
4 changes: 2 additions & 2 deletions storage/api/Storage.Samples.Tests/MakePublicTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Google Inc.
// Copyright 2020 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -26,7 +26,7 @@ public MakePublicTest(StorageFixture fixture)
_fixture = fixture;
}

[Fact]
[Fact(Skip = "b/477676781")]
public void MakePublic()
{
MakePublicSample makePublicSample = new MakePublicSample();
Expand Down
4 changes: 2 additions & 2 deletions storage/api/Storage.Samples.Tests/StorageFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ public void DeleteHmacKey(string accessId, bool isActive)
} while (true);
}

public void CreateBucket(string bucketName, string location = null, AutoclassData autoclassData = null)
public void CreateBucket(string bucketName, string location = null, AutoclassData autoclassData = null, string storageClass = null)
{
StorageClient storageClient = StorageClient.Create();
storageClient.CreateBucket(ProjectId, new Bucket { Name = bucketName, Location = location, Autoclass = autoclassData });
storageClient.CreateBucket(ProjectId, new Bucket { Name = bucketName, Location = location, Autoclass = autoclassData, StorageClass = storageClass });
SleepAfterBucketCreateUpdateDelete();
TempBucketNames.Add(bucketName);
}
Expand Down
65 changes: 65 additions & 0 deletions storage/api/Storage.Samples/ListBucketsWithPartialSuccess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2025 Google LLC
//
// 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.

// [START storage_list_buckets_partial_success]

using Google.Api.Gax;
using Google.Apis.Storage.v1.Data;
using Google.Cloud.Storage.V1;
using System;
using System.Collections.Generic;
using System.Linq;

public class ListBucketsWithPartialSuccessSample
Comment thread
mahendra-google marked this conversation as resolved.
{
/// <summary>
/// Lists buckets, returning both the reachable buckets and the resource names of buckets from unreachable locations when specific regions are unreachable.
/// </summary>
/// <param name="projectId">The ID of the project to list the buckets.</param>
public (IReadOnlyList<Bucket> Reachable, IReadOnlyList<string> Unreachable) ListBucketsWithPartialSuccess
(string projectId = "your-project-id")
{
var storage = StorageClient.Create();
var pagedResult = storage.ListBuckets(projectId, options: new ListBucketsOptions
{
ReturnPartialSuccess = true
});

var reachableBuckets = new List<Bucket>();
var unreachableBuckets = new List<string>();

foreach (var page in pagedResult.AsRawResponses())
{
reachableBuckets.AddRange(page.Items ?? Enumerable.Empty<Bucket>());
unreachableBuckets.AddRange(page.Unreachable ?? Enumerable.Empty<string>());
}
Comment thread
mahendra-google marked this conversation as resolved.

Console.WriteLine("Buckets:");
foreach (var bucket in reachableBuckets)
{
Console.WriteLine(bucket.Name);
}

if (unreachableBuckets.Any())
{
Console.WriteLine("The Resource Names of Buckets from Unreachable Locations:");
foreach (var bucket in unreachableBuckets)
{
Console.WriteLine(bucket);
}
}
return (reachableBuckets, unreachableBuckets);
}
}
// [END storage_list_buckets_partial_success]
2 changes: 1 addition & 1 deletion storage/api/Storage.Samples/Storage.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="Google.Cloud.Storage.Control.V2" Version="1.5.0" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.13.0" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.14.0" />
</ItemGroup>

</Project>