diff --git a/google/cloud/storage/bucket_test.cc b/google/cloud/storage/bucket_test.cc index 4be704781d73e..9c03909ca4bc4 100644 --- a/google/cloud/storage/bucket_test.cc +++ b/google/cloud/storage/bucket_test.cc @@ -29,6 +29,7 @@ namespace storage { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN namespace { +using ::google::cloud::internal::CurrentOptions; using ::google::cloud::storage::testing::canonical_errors::TransientError; using ::testing::ElementsAre; using ::testing::ElementsAreArray; @@ -76,6 +77,8 @@ TEST_F(BucketTest, CreateBucket) { EXPECT_CALL(*mock_, CreateBucket) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([&expected](internal::CreateBucketRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket-name", r.metadata().name()); EXPECT_EQ("US", r.metadata().location()); EXPECT_EQ("STANDARD", r.metadata().storage_class()); @@ -85,7 +88,8 @@ TEST_F(BucketTest, CreateBucket) { auto client = ClientForMock(); auto actual = client.CreateBucket( "test-bucket-name", - BucketMetadata().set_location("US").set_storage_class("STANDARD")); + BucketMetadata().set_location("US").set_storage_class("STANDARD"), + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(expected, *actual); } @@ -135,11 +139,14 @@ TEST_F(BucketTest, GetBucketMetadata) { EXPECT_CALL(*mock_, GetBucketMetadata) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([&expected](internal::GetBucketMetadataRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("foo-bar-baz", r.bucket_name()); return make_status_or(expected); }); auto client = ClientForMock(); - auto actual = client.GetBucketMetadata("foo-bar-baz"); + auto actual = client.GetBucketMetadata( + "foo-bar-baz", Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(expected, *actual); } @@ -167,11 +174,14 @@ TEST_F(BucketTest, DeleteBucket) { EXPECT_CALL(*mock_, DeleteBucket) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([](internal::DeleteBucketRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("foo-bar-baz", r.bucket_name()); return make_status_or(internal::EmptyResponse{}); }); auto client = ClientForMock(); - auto status = client.DeleteBucket("foo-bar-baz"); + auto status = client.DeleteBucket( + "foo-bar-baz", Options{}.set("u-p-test")); ASSERT_STATUS_OK(status); } @@ -214,6 +224,8 @@ TEST_F(BucketTest, UpdateBucket) { EXPECT_CALL(*mock_, UpdateBucket) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([&expected](internal::UpdateBucketRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket-name", r.metadata().name()); EXPECT_EQ("US", r.metadata().location()); EXPECT_EQ("STANDARD", r.metadata().storage_class()); @@ -222,7 +234,8 @@ TEST_F(BucketTest, UpdateBucket) { auto client = ClientForMock(); auto actual = client.UpdateBucket( "test-bucket-name", - BucketMetadata().set_location("US").set_storage_class("STANDARD")); + BucketMetadata().set_location("US").set_storage_class("STANDARD"), + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(expected, *actual); } @@ -273,6 +286,8 @@ TEST_F(BucketTest, PatchBucket) { EXPECT_CALL(*mock_, PatchBucket) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([&expected](internal::PatchBucketRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket-name", r.bucket()); EXPECT_THAT(r.payload(), HasSubstr("STANDARD")); return make_status_or(expected); @@ -280,7 +295,8 @@ TEST_F(BucketTest, PatchBucket) { auto client = ClientForMock(); auto actual = client.PatchBucket( "test-bucket-name", - BucketMetadataPatchBuilder().SetStorageClass("STANDARD")); + BucketMetadataPatchBuilder().SetStorageClass("STANDARD"), + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(expected, *actual); } @@ -321,11 +337,14 @@ TEST_F(BucketTest, GetNativeBucketIamPolicy) { EXPECT_CALL(*mock_, GetNativeBucketIamPolicy) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([&expected](internal::GetBucketIamPolicyRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket-name", r.bucket_name()); return make_status_or(expected); }); auto client = ClientForMock(); - auto actual = client.GetNativeBucketIamPolicy("test-bucket-name"); + auto actual = client.GetNativeBucketIamPolicy( + "test-bucket-name", Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(0, actual->version()); EXPECT_EQ("XYZ=", actual->etag()); @@ -359,12 +378,16 @@ TEST_F(BucketTest, SetNativeBucketIamPolicy) { .WillOnce(Return(StatusOr(TransientError()))) .WillOnce( [&expected](internal::SetNativeBucketIamPolicyRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket-name", r.bucket_name()); EXPECT_THAT(r.json_payload(), HasSubstr("test-user")); return make_status_or(expected); }); auto client = ClientForMock(); - auto actual = client.SetNativeBucketIamPolicy("test-bucket-name", expected); + auto actual = client.SetNativeBucketIamPolicy( + "test-bucket-name", expected, + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_EQ(0, actual->version()); EXPECT_EQ("XYZ=", actual->etag()); @@ -412,13 +435,16 @@ TEST_F(BucketTest, TestBucketIamPermissions) { TransientError()))) .WillOnce( [&expected](internal::TestBucketIamPermissionsRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket-name", r.bucket_name()); EXPECT_THAT(r.permissions(), ElementsAre("storage.buckets.delete")); return make_status_or(expected); }); auto client = ClientForMock(); - auto actual = client.TestBucketIamPermissions("test-bucket-name", - {"storage.buckets.delete"}); + auto actual = client.TestBucketIamPermissions( + "test-bucket-name", {"storage.buckets.delete"}, + Options{}.set("u-p-test")); ASSERT_STATUS_OK(actual); EXPECT_THAT(*actual, ElementsAreArray(expected.permissions)); } @@ -464,12 +490,15 @@ TEST_F(BucketTest, LockBucketRetentionPolicy) { .WillOnce(Return(StatusOr(TransientError()))) .WillOnce( [expected](internal::LockBucketRetentionPolicyRequest const& r) { + EXPECT_EQ(CurrentOptions().get(), "a-default"); + EXPECT_EQ(CurrentOptions().get(), "u-p-test"); EXPECT_EQ("test-bucket-name", r.bucket_name()); EXPECT_EQ(42, r.metageneration()); return make_status_or(expected); }); auto client = ClientForMock(); - auto metadata = client.LockBucketRetentionPolicy("test-bucket-name", 42U); + auto metadata = client.LockBucketRetentionPolicy( + "test-bucket-name", 42U, Options{}.set("u-p-test")); ASSERT_STATUS_OK(metadata); EXPECT_EQ(expected, *metadata); } diff --git a/google/cloud/storage/client.h b/google/cloud/storage/client.h index c2006762910a4..03e9d0120c6da 100644 --- a/google/cloud/storage/client.h +++ b/google/cloud/storage/client.h @@ -397,6 +397,7 @@ class Client { template ListBucketsReader ListBucketsForProject(std::string const& project_id, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::ListBucketsRequest request(project_id); request.set_multiple_options(std::forward(options)...); auto client = raw_client_; @@ -430,6 +431,7 @@ class Client { */ template ListBucketsReader ListBuckets(Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); auto const& project_id = raw_client_->client_options().project_id(); return ListBucketsForProject(project_id, std::forward(options)...); } @@ -502,6 +504,7 @@ class Client { std::string project_id, BucketMetadata metadata, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); metadata.set_name(std::move(bucket_name)); internal::CreateBucketRequest request(std::move(project_id), std::move(metadata)); @@ -526,6 +529,7 @@ class Client { template StatusOr GetBucketMetadata(std::string const& bucket_name, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::GetBucketMetadataRequest request(bucket_name); request.set_multiple_options(std::forward(options)...); return raw_client_->GetBucketMetadata(request); @@ -548,6 +552,7 @@ class Client { */ template Status DeleteBucket(std::string const& bucket_name, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::DeleteBucketRequest request(bucket_name); request.set_multiple_options(std::forward(options)...); return raw_client_->DeleteBucket(request).status(); @@ -590,6 +595,7 @@ class Client { StatusOr UpdateBucket(std::string bucket_name, BucketMetadata metadata, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); metadata.set_name(std::move(bucket_name)); internal::UpdateBucketRequest request(std::move(metadata)); request.set_multiple_options(std::forward(options)...); @@ -639,6 +645,7 @@ class Client { BucketMetadata const& original, BucketMetadata const& updated, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::PatchBucketRequest request(std::move(bucket_name), original, updated); request.set_multiple_options(std::forward(options)...); @@ -682,6 +689,7 @@ class Client { StatusOr PatchBucket( std::string bucket_name, BucketMetadataPatchBuilder const& builder, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::PatchBucketRequest request(std::move(bucket_name), builder); request.set_multiple_options(std::forward(options)...); return raw_client_->PatchBucket(request); @@ -723,6 +731,7 @@ class Client { template StatusOr GetNativeBucketIamPolicy( std::string const& bucket_name, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::GetBucketIamPolicyRequest request(bucket_name); request.set_multiple_options(std::forward(options)...); return raw_client_->GetNativeBucketIamPolicy(request); @@ -778,6 +787,7 @@ class Client { StatusOr SetNativeBucketIamPolicy( std::string const& bucket_name, NativeIamPolicy const& iam_policy, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::SetNativeBucketIamPolicyRequest request(bucket_name, iam_policy); request.set_multiple_options(std::forward(options)...); return raw_client_->SetNativeBucketIamPolicy(request); @@ -814,6 +824,7 @@ class Client { StatusOr> TestBucketIamPermissions( std::string bucket_name, std::vector permissions, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::TestBucketIamPermissionsRequest request(std::move(bucket_name), std::move(permissions)); request.set_multiple_options(std::forward(options)...); @@ -874,6 +885,7 @@ class Client { StatusOr LockBucketRetentionPolicy( std::string const& bucket_name, std::uint64_t metageneration, Options&&... options) { + auto const span = MakeSpan(std::forward(options)...); internal::LockBucketRetentionPolicyRequest request(bucket_name, metageneration); request.set_multiple_options(std::forward(options)...);