From eb2caccb6ebfb14f27cea6ee1f94680966fcdf67 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Thu, 18 Jul 2024 14:25:34 +0000 Subject: [PATCH] cleanup(storage): simplify test initialization (#14490) Another round of cleanups on test initialization. --- .../grpc_bucket_metadata_integration_test.cc | 56 ++++++++-------- .../tests/grpc_hmac_key_integration_test.cc | 12 ++-- .../storage/tests/grpc_integration_test.cc | 60 +++++++---------- .../tests/grpc_object_acl_integration_test.cc | 64 +++++++++---------- .../grpc_object_media_integration_test.cc | 10 ++- .../grpc_object_metadata_integration_test.cc | 56 ++++++++-------- .../grpc_service_account_integration_test.cc | 5 +- 7 files changed, 120 insertions(+), 143 deletions(-) diff --git a/google/cloud/storage/tests/grpc_bucket_metadata_integration_test.cc b/google/cloud/storage/tests/grpc_bucket_metadata_integration_test.cc index c32e52beb5418..c1474f5812076 100644 --- a/google/cloud/storage/tests/grpc_bucket_metadata_integration_test.cc +++ b/google/cloud/storage/tests/grpc_bucket_metadata_integration_test.cc @@ -51,17 +51,16 @@ TEST_F(GrpcBucketMetadataIntegrationTest, BucketMetadataCRUD) { ASSERT_THAT(project_name, Not(IsEmpty())) << "GOOGLE_CLOUD_PROJECT is not set"; - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); + auto client = MakeIntegrationTestClient(Options{}); auto bucket_name = MakeRandomBucketName(); - auto insert = client->CreateBucketForProject(bucket_name, project_name, - BucketMetadata()); + auto insert = client.CreateBucketForProject(bucket_name, project_name, + BucketMetadata()); ASSERT_STATUS_OK(insert); ScheduleForDelete(*insert); EXPECT_EQ(insert->name(), bucket_name); - auto get = client->GetBucketMetadata(bucket_name); + auto get = client.GetBucketMetadata(bucket_name); ASSERT_STATUS_OK(get); // There are too many fields with missing values in the testbench, just test @@ -77,21 +76,21 @@ TEST_F(GrpcBucketMetadataIntegrationTest, BucketMetadataCRUD) { // We need to set the retention policy or the request to lock the retention // policy (see below) will fail. - auto patch = client->PatchBucket( + auto patch = client.PatchBucket( bucket_name, BucketMetadataPatchBuilder{} .SetLabel("l0", "k0") .SetRetentionPolicy(std::chrono::seconds(30))); ASSERT_STATUS_OK(patch); EXPECT_THAT(patch->labels(), ElementsAre(Pair("l0", "k0"))); - auto updated = client->UpdateBucket( + auto updated = client.UpdateBucket( patch->name(), BucketMetadata(*patch).upsert_label("l1", "test-value")); ASSERT_STATUS_OK(updated); EXPECT_THAT(updated->labels(), UnorderedElementsAre(Pair("l0", "k0"), Pair("l1", "test-value"))); auto locked = - client->LockBucketRetentionPolicy(bucket_name, updated->metageneration()); + client.LockBucketRetentionPolicy(bucket_name, updated->metageneration()); ASSERT_STATUS_OK(locked); ASSERT_TRUE(updated->has_retention_policy()); ASSERT_TRUE(locked->has_retention_policy()); @@ -100,19 +99,19 @@ TEST_F(GrpcBucketMetadataIntegrationTest, BucketMetadataCRUD) { // Create a second bucket to make the list more interesting. auto bucket_name_2 = MakeRandomBucketName(); - auto insert_2 = client->CreateBucketForProject(bucket_name_2, project_name, - BucketMetadata()); + auto insert_2 = client.CreateBucketForProject(bucket_name_2, project_name, + BucketMetadata()); ASSERT_STATUS_OK(insert_2); ScheduleForDelete(*insert_2); std::vector names; - for (auto const& b : client->ListBucketsForProject(project_name)) { + for (auto const& b : client.ListBucketsForProject(project_name)) { ASSERT_STATUS_OK(b); names.push_back(b->name()); } EXPECT_THAT(names, IsSupersetOf({bucket_name, bucket_name_2})); - auto policy = client->GetNativeBucketIamPolicy(bucket_name); + auto policy = client.GetNativeBucketIamPolicy(bucket_name); ASSERT_STATUS_OK(policy); std::vector roles; @@ -123,18 +122,18 @@ TEST_F(GrpcBucketMetadataIntegrationTest, BucketMetadataCRUD) { "roles/storage.legacyBucketReader"})); auto new_policy = *policy; - policy = client->SetNativeBucketIamPolicy(bucket_name, new_policy); + policy = client.SetNativeBucketIamPolicy(bucket_name, new_policy); ASSERT_STATUS_OK(policy); - auto permissions = client->TestBucketIamPermissions( + auto permissions = client.TestBucketIamPermissions( bucket_name, {"storage.objects.list", "storage.buckets.update"}); ASSERT_STATUS_OK(permissions); EXPECT_THAT(*permissions, Contains("storage.buckets.update")); - auto delete_status = client->DeleteBucket(bucket_name); + auto delete_status = client.DeleteBucket(bucket_name); ASSERT_STATUS_OK(delete_status); - auto post_delete = client->GetBucketMetadata(bucket_name); + auto post_delete = client.GetBucketMetadata(bucket_name); EXPECT_THAT(post_delete, StatusIs(StatusCode::kNotFound)); } @@ -146,30 +145,29 @@ TEST_F(GrpcBucketMetadataIntegrationTest, PatchLabels) { ASSERT_THAT(project_name, Not(IsEmpty())) << "GOOGLE_CLOUD_PROJECT is not set"; - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto bucket_name = MakeRandomBucketName(); - auto insert = client->CreateBucketForProject(bucket_name, project_name, - BucketMetadata()); + + auto insert = client.CreateBucketForProject(bucket_name, project_name, + BucketMetadata()); ASSERT_STATUS_OK(insert); ScheduleForDelete(*insert); EXPECT_EQ(insert->name(), bucket_name); auto patch = - client->PatchBucket(bucket_name, BucketMetadataPatchBuilder{} - .SetLabel("test-key0", "v0") - .SetLabel("test-key1", "v1") - .SetLabel("test-key2", "v2")); + client.PatchBucket(bucket_name, BucketMetadataPatchBuilder{} + .SetLabel("test-key0", "v0") + .SetLabel("test-key1", "v1") + .SetLabel("test-key2", "v2")); ASSERT_STATUS_OK(patch); EXPECT_THAT(patch->labels(), AllOf(Contains(Pair("test-key0", "v0")), Contains(Pair("test-key1", "v1")), Contains(Pair("test-key2", "v2")))); - patch = client->PatchBucket(bucket_name, BucketMetadataPatchBuilder{} - .SetLabel("test-key0", "new-v0") - .ResetLabel("test-key1") - .SetLabel("test-key3", "v3")); + patch = client.PatchBucket(bucket_name, BucketMetadataPatchBuilder{} + .SetLabel("test-key0", "new-v0") + .ResetLabel("test-key1") + .SetLabel("test-key3", "v3")); ASSERT_STATUS_OK(patch); EXPECT_THAT(patch->labels(), AllOf(Contains(Pair("test-key0", "new-v0")), Not(Contains(Pair("test-key1", _))), diff --git a/google/cloud/storage/tests/grpc_hmac_key_integration_test.cc b/google/cloud/storage/tests/grpc_hmac_key_integration_test.cc index 813efb8c43af9..2ca9edbea44fb 100644 --- a/google/cloud/storage/tests/grpc_hmac_key_integration_test.cc +++ b/google/cloud/storage/tests/grpc_hmac_key_integration_test.cc @@ -51,11 +51,11 @@ TEST_F(GrpcHmacKeyMetadataIntegrationTest, HmacKeyCRUD) { ScopedEnvironment grpc_config("GOOGLE_CLOUD_CPP_STORAGE_GRPC_CONFIG", "metadata"); - auto client = MakeIntegrationTestClient(); + auto client = MakeIntegrationTestClient(Options{}); auto get_ids = [&] { std::vector ids; - auto range = client->ListHmacKeys(ServiceAccountFilter(service_account)); + auto range = client.ListHmacKeys(ServiceAccountFilter(service_account)); std::transform(range.begin(), range.end(), std::back_inserter(ids), [](StatusOr x) { return x.value().id(); }); return ids; @@ -63,7 +63,7 @@ TEST_F(GrpcHmacKeyMetadataIntegrationTest, HmacKeyCRUD) { auto const initial_ids = get_ids(); - auto create = client->CreateHmacKey(service_account); + auto create = client.CreateHmacKey(service_account); ASSERT_STATUS_OK(create); auto const key = create->second; auto const metadata = create->first; @@ -73,18 +73,18 @@ TEST_F(GrpcHmacKeyMetadataIntegrationTest, HmacKeyCRUD) { auto current_ids = get_ids(); EXPECT_THAT(current_ids, Contains(metadata.id())); - auto get = client->GetHmacKey(metadata.access_id()); + auto get = client.GetHmacKey(metadata.access_id()); ASSERT_STATUS_OK(get); EXPECT_EQ(*get, metadata); // Before we can delete the HmacKey we need to move it to the inactive state. auto update = metadata; update.set_state(HmacKeyMetadata::state_inactive()); - auto update_response = client->UpdateHmacKey(update.access_id(), update); + auto update_response = client.UpdateHmacKey(update.access_id(), update); ASSERT_STATUS_OK(update_response); EXPECT_EQ(update_response->state(), HmacKeyMetadata::state_inactive()); - auto delete_response = client->DeleteHmacKey(get->access_id()); + auto delete_response = client.DeleteHmacKey(get->access_id()); ASSERT_STATUS_OK(delete_response); current_ids = get_ids(); diff --git a/google/cloud/storage/tests/grpc_integration_test.cc b/google/cloud/storage/tests/grpc_integration_test.cc index 87aefdb232126..bfea01209e96e 100644 --- a/google/cloud/storage/tests/grpc_integration_test.cc +++ b/google/cloud/storage/tests/grpc_integration_test.cc @@ -63,30 +63,28 @@ class GrpcIntegrationTest TEST_P(GrpcIntegrationTest, ObjectCRUD) { auto bucket_client = MakeBucketIntegrationTestClient(); - - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto bucket_name = MakeRandomBucketName(); auto object_name = MakeRandomObjectName(); + auto bucket_metadata = bucket_client.CreateBucketForProject( bucket_name, project_id(), BucketMetadata()); ASSERT_STATUS_OK(bucket_metadata); EXPECT_EQ(bucket_name, bucket_metadata->name()); - auto object_metadata = client->InsertObject( + auto object_metadata = client.InsertObject( bucket_name, object_name, LoremIpsum(), IfGenerationMatch(0)); ASSERT_STATUS_OK(object_metadata); - auto stream = client->ReadObject(bucket_name, object_name); + auto stream = client.ReadObject(bucket_name, object_name); std::string actual(std::istreambuf_iterator{stream}, {}); EXPECT_EQ(LoremIpsum(), actual); EXPECT_STATUS_OK(stream.status()); // This is part of the test, not just a cleanup. - auto delete_object_status = client->DeleteObject( + auto delete_object_status = client.DeleteObject( bucket_name, object_name, Generation(object_metadata->generation())); EXPECT_STATUS_OK(delete_object_status); @@ -96,12 +94,10 @@ TEST_P(GrpcIntegrationTest, ObjectCRUD) { TEST_P(GrpcIntegrationTest, WriteResume) { auto bucket_client = MakeBucketIntegrationTestClient(); - - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto bucket_name = MakeRandomBucketName(); auto object_name = MakeRandomObjectName(); + auto bucket_metadata = bucket_client.CreateBucketForProject( bucket_name, project_id(), BucketMetadata()); ASSERT_STATUS_OK(bucket_metadata); @@ -113,15 +109,15 @@ TEST_P(GrpcIntegrationTest, WriteResume) { std::string session_id; { auto old_os = - client->WriteObject(bucket_name, object_name, IfGenerationMatch(0), - NewResumableUploadSession()); + client.WriteObject(bucket_name, object_name, IfGenerationMatch(0), + NewResumableUploadSession()); ASSERT_TRUE(old_os.good()) << "status=" << old_os.metadata().status(); session_id = old_os.resumable_session_id(); std::move(old_os).Suspend(); } - auto os = client->WriteObject(bucket_name, object_name, - RestoreResumableUploadSession(session_id)); + auto os = client.WriteObject(bucket_name, object_name, + RestoreResumableUploadSession(session_id)); ASSERT_TRUE(os.good()) << "status=" << os.metadata().status(); EXPECT_EQ(session_id, os.resumable_session_id()); os << LoremIpsum(); @@ -137,7 +133,7 @@ TEST_P(GrpcIntegrationTest, WriteResume) { EXPECT_EQ("resumable", meta.metadata("x_emulator_upload")); } - auto status = client->DeleteObject(bucket_name, object_name); + auto status = client.DeleteObject(bucket_name, object_name); EXPECT_STATUS_OK(status); auto delete_bucket_status = bucket_client.DeleteBucket(bucket_name); @@ -146,12 +142,10 @@ TEST_P(GrpcIntegrationTest, WriteResume) { TEST_P(GrpcIntegrationTest, InsertLarge) { auto bucket_client = MakeBucketIntegrationTestClient(); - - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto bucket_name = MakeRandomBucketName(); auto object_name = MakeRandomObjectName(); + auto bucket_metadata = bucket_client.CreateBucketForProject( bucket_name, project_id(), BucketMetadata()); ASSERT_STATUS_OK(bucket_metadata); @@ -161,8 +155,8 @@ TEST_P(GrpcIntegrationTest, InsertLarge) { // multiple of 256 KiB. auto const desired_size = 8 * 1024 * 1024L + 253 * 1024 + 15; auto data = MakeRandomData(desired_size); - auto metadata = client->InsertObject(bucket_name, object_name, data, - IfGenerationMatch(0)); + auto metadata = + client.InsertObject(bucket_name, object_name, data, IfGenerationMatch(0)); ASSERT_STATUS_OK(metadata); ScheduleForDelete(*metadata); @@ -171,12 +165,10 @@ TEST_P(GrpcIntegrationTest, InsertLarge) { TEST_P(GrpcIntegrationTest, StreamLargeChunks) { auto bucket_client = MakeBucketIntegrationTestClient(); - - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto bucket_name = MakeRandomBucketName(); auto object_name = MakeRandomObjectName(); + auto bucket_metadata = bucket_client.CreateBucketForProject( bucket_name, project_id(), BucketMetadata()); ASSERT_STATUS_OK(bucket_metadata); @@ -186,7 +178,7 @@ TEST_P(GrpcIntegrationTest, StreamLargeChunks) { auto const desired_size = 8 * 1024 * 1024L; auto data = MakeRandomData(desired_size); auto stream = - client->WriteObject(bucket_name, object_name, IfGenerationMatch(0)); + client.WriteObject(bucket_name, object_name, IfGenerationMatch(0)); stream.write(data.data(), data.size()); EXPECT_TRUE(stream.good()); stream.write(data.data(), data.size()); @@ -200,14 +192,12 @@ TEST_P(GrpcIntegrationTest, StreamLargeChunks) { } TEST_P(GrpcIntegrationTest, QuotaUser) { - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto object_name = MakeRandomObjectName(); auto metadata = - client->InsertObject(bucket_name(), object_name, LoremIpsum(), - IfGenerationMatch(0), QuotaUser("test-only")); + client.InsertObject(bucket_name(), object_name, LoremIpsum(), + IfGenerationMatch(0), QuotaUser("test-only")); ASSERT_STATUS_OK(metadata); ScheduleForDelete(*metadata); } @@ -217,12 +207,10 @@ TEST_P(GrpcIntegrationTest, FieldFilter) { auto const* fields = UsingGrpc() ? "resource.bucket,resource.name,resource." "generation,resource.content_type" : "bucket,name,generation,contentType"; - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto object_name = MakeRandomObjectName(); - auto metadata = client->InsertObject( + auto metadata = client.InsertObject( bucket_name(), object_name, LoremIpsum(), IfGenerationMatch(0), ContentType("text/plain"), ContentEncoding("utf-8"), Fields(fields)); ASSERT_STATUS_OK(metadata); diff --git a/google/cloud/storage/tests/grpc_object_acl_integration_test.cc b/google/cloud/storage/tests/grpc_object_acl_integration_test.cc index 544227a5f82c9..8b0a40853e1d9 100644 --- a/google/cloud/storage/tests/grpc_object_acl_integration_test.cc +++ b/google/cloud/storage/tests/grpc_object_acl_integration_test.cc @@ -48,13 +48,11 @@ TEST_F(GrpcObjectAclIntegrationTest, AclCRUD) { auto const project_id = GetEnv("GOOGLE_CLOUD_PROJECT").value_or(""); ASSERT_THAT(project_id, Not(IsEmpty())) << "GOOGLE_CLOUD_PROJECT is not set"; - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - - // Create a new object to run the tests. + auto client = MakeIntegrationTestClient(Options{}); auto object_name = MakeRandomObjectName(); - auto insert = client->InsertObject(bucket_name, object_name, LoremIpsum(), - IfGenerationMatch(0), Projection::Full()); + + auto insert = client.InsertObject(bucket_name, object_name, LoremIpsum(), + IfGenerationMatch(0), Projection::Full()); ASSERT_STATUS_OK(insert); ScheduleForDelete(*insert); @@ -71,83 +69,83 @@ TEST_F(GrpcObjectAclIntegrationTest, AclCRUD) { << " created with a predefined ACL which should preclude this result."; auto const existing_entity = insert->acl().front(); - auto current_acl = client->ListObjectAcl(bucket_name, object_name); + auto current_acl = client.ListObjectAcl(bucket_name, object_name); ASSERT_STATUS_OK(current_acl); EXPECT_THAT(AclEntityNames(*current_acl), Contains(existing_entity.entity()).Times(1)); - auto create_acl = client->CreateObjectAcl(bucket_name, object_name, viewers, - BucketAccessControl::ROLE_READER()); + auto create_acl = client.CreateObjectAcl(bucket_name, object_name, viewers, + BucketAccessControl::ROLE_READER()); ASSERT_STATUS_OK(create_acl); - current_acl = client->ListObjectAcl(bucket_name, object_name); + current_acl = client.ListObjectAcl(bucket_name, object_name); ASSERT_STATUS_OK(current_acl); EXPECT_THAT(AclEntityNames(*current_acl), Contains(create_acl->entity()).Times(1)); - auto c2 = client->CreateObjectAcl(bucket_name, object_name, viewers, - BucketAccessControl::ROLE_READER()); + auto c2 = client.CreateObjectAcl(bucket_name, object_name, viewers, + BucketAccessControl::ROLE_READER()); ASSERT_STATUS_OK(c2); // There is no guarantee that the ETag remains unchanged, even if the // operation has no effect. Reset the one field that might change. create_acl->set_etag(c2->etag()); EXPECT_EQ(*create_acl, *c2); - auto get_acl = client->GetObjectAcl(bucket_name, object_name, viewers); + auto get_acl = client.GetObjectAcl(bucket_name, object_name, viewers); ASSERT_STATUS_OK(get_acl); EXPECT_EQ(*c2, *get_acl); auto not_found_acl = - client->GetObjectAcl(bucket_name, object_name, "not-found-entity"); + client.GetObjectAcl(bucket_name, object_name, "not-found-entity"); EXPECT_THAT(not_found_acl, StatusIs(StatusCode::kNotFound)); - auto updated_acl = client->UpdateObjectAcl( - bucket_name, object_name, - ObjectAccessControl().set_entity(viewers).set_role( - ObjectAccessControl::ROLE_OWNER())); + auto updated_acl = + client.UpdateObjectAcl(bucket_name, object_name, + ObjectAccessControl().set_entity(viewers).set_role( + ObjectAccessControl::ROLE_OWNER())); ASSERT_STATUS_OK(updated_acl); EXPECT_EQ(updated_acl->entity(), create_acl->entity()); EXPECT_EQ(updated_acl->role(), ObjectAccessControl::ROLE_OWNER()); // "Updating" an entity that does not exist should create the entity - auto delete_acl = client->DeleteObjectAcl(bucket_name, object_name, viewers); + auto delete_acl = client.DeleteObjectAcl(bucket_name, object_name, viewers); ASSERT_STATUS_OK(delete_acl); - updated_acl = client->UpdateObjectAcl( - bucket_name, object_name, - ObjectAccessControl().set_entity(viewers).set_role( - ObjectAccessControl::ROLE_OWNER())); + updated_acl = + client.UpdateObjectAcl(bucket_name, object_name, + ObjectAccessControl().set_entity(viewers).set_role( + ObjectAccessControl::ROLE_OWNER())); ASSERT_STATUS_OK(updated_acl); EXPECT_EQ(updated_acl->entity(), create_acl->entity()); EXPECT_EQ(updated_acl->role(), ObjectAccessControl::ROLE_OWNER()); auto patched_acl = - client->PatchObjectAcl(bucket_name, object_name, create_acl->entity(), - ObjectAccessControlPatchBuilder().set_role( - ObjectAccessControl::ROLE_READER())); + client.PatchObjectAcl(bucket_name, object_name, create_acl->entity(), + ObjectAccessControlPatchBuilder().set_role( + ObjectAccessControl::ROLE_READER())); ASSERT_STATUS_OK(patched_acl); EXPECT_EQ(patched_acl->entity(), create_acl->entity()); EXPECT_EQ(patched_acl->role(), ObjectAccessControl::ROLE_READER()); // "Patching" an entity that does not exist should create the entity - delete_acl = client->DeleteObjectAcl(bucket_name, object_name, viewers); + delete_acl = client.DeleteObjectAcl(bucket_name, object_name, viewers); ASSERT_STATUS_OK(delete_acl); patched_acl = - client->PatchObjectAcl(bucket_name, object_name, create_acl->entity(), - ObjectAccessControlPatchBuilder().set_role( - ObjectAccessControl::ROLE_READER())); + client.PatchObjectAcl(bucket_name, object_name, create_acl->entity(), + ObjectAccessControlPatchBuilder().set_role( + ObjectAccessControl::ROLE_READER())); ASSERT_STATUS_OK(patched_acl); EXPECT_EQ(patched_acl->entity(), create_acl->entity()); EXPECT_EQ(patched_acl->role(), ObjectAccessControl::ROLE_READER()); - delete_acl = client->DeleteObjectAcl(bucket_name, object_name, viewers); + delete_acl = client.DeleteObjectAcl(bucket_name, object_name, viewers); ASSERT_STATUS_OK(delete_acl); - current_acl = client->ListObjectAcl(bucket_name, object_name); + current_acl = client.ListObjectAcl(bucket_name, object_name); ASSERT_STATUS_OK(current_acl); EXPECT_THAT(AclEntityNames(*current_acl), Not(Contains(create_acl->entity()))); - auto status = client->DeleteObject(bucket_name, object_name); + auto status = client.DeleteObject(bucket_name, object_name); ASSERT_STATUS_OK(status); } diff --git a/google/cloud/storage/tests/grpc_object_media_integration_test.cc b/google/cloud/storage/tests/grpc_object_media_integration_test.cc index 992728e72e203..9af855fc5025a 100644 --- a/google/cloud/storage/tests/grpc_object_media_integration_test.cc +++ b/google/cloud/storage/tests/grpc_object_media_integration_test.cc @@ -43,18 +43,16 @@ TEST_F(GrpcObjectMediaIntegrationTest, CancelResumableUpload) { ASSERT_THAT(bucket_name, Not(IsEmpty())) << "GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME is not set"; - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto object_name = MakeRandomObjectName(); // Start an upload, capture its upload ID and suspend it. - auto os = client->WriteObject(bucket_name, object_name, IfGenerationMatch(0), - NewResumableUploadSession()); + auto os = client.WriteObject(bucket_name, object_name, IfGenerationMatch(0), + NewResumableUploadSession()); auto const upload_id = os.resumable_session_id(); std::move(os).Suspend(); - auto status = client->DeleteResumableUpload(upload_id); + auto status = client.DeleteResumableUpload(upload_id); EXPECT_STATUS_OK(status); } diff --git a/google/cloud/storage/tests/grpc_object_metadata_integration_test.cc b/google/cloud/storage/tests/grpc_object_metadata_integration_test.cc index 661526c1dd576..398bbc2c8ebfb 100644 --- a/google/cloud/storage/tests/grpc_object_metadata_integration_test.cc +++ b/google/cloud/storage/tests/grpc_object_metadata_integration_test.cc @@ -48,49 +48,47 @@ TEST_F(GrpcObjectMetadataIntegrationTest, ObjectMetadataCRUD) { ASSERT_THAT(bucket_name, Not(IsEmpty())) << "GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME is not set"; - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto object_name = MakeRandomObjectName(); auto rewrite_name = MakeRandomObjectName(); auto copy_name = MakeRandomObjectName(); auto compose_name = MakeRandomObjectName(); // Use the full projection to get consistent behavior out of gRPC and REST. - auto insert = client->InsertObject(bucket_name, object_name, LoremIpsum(), - IfGenerationMatch(0), Projection::Full()); + auto insert = client.InsertObject(bucket_name, object_name, LoremIpsum(), + IfGenerationMatch(0), Projection::Full()); ASSERT_STATUS_OK(insert); ScheduleForDelete(*insert); auto get = - client->GetObjectMetadata(bucket_name, object_name, Projection::Full()); + client.GetObjectMetadata(bucket_name, object_name, Projection::Full()); ASSERT_STATUS_OK(get); EXPECT_EQ(*insert, *get); std::vector names; - for (auto const& object : client->ListObjects(bucket_name)) { + for (auto const& object : client.ListObjects(bucket_name)) { ASSERT_STATUS_OK(object); names.push_back(object->name()); } EXPECT_THAT(names, Contains(object_name)); - auto rewrite = client->RewriteObjectBlocking(bucket_name, object_name, - bucket_name, rewrite_name); + auto rewrite = client.RewriteObjectBlocking(bucket_name, object_name, + bucket_name, rewrite_name); ASSERT_STATUS_OK(rewrite); ScheduleForDelete(*rewrite); auto copy = - client->CopyObject(bucket_name, object_name, bucket_name, rewrite_name); + client.CopyObject(bucket_name, object_name, bucket_name, rewrite_name); ASSERT_STATUS_OK(copy); ScheduleForDelete(*copy); - auto patch = client->PatchObject( + auto patch = client.PatchObject( bucket_name, object_name, ObjectMetadataPatchBuilder{}.SetCacheControl("no-cache")); ASSERT_STATUS_OK(patch); EXPECT_EQ(patch->cache_control(), "no-cache"); - auto compose = client->ComposeObject( + auto compose = client.ComposeObject( bucket_name, { ComposeSourceObject{object_name, absl::nullopt, absl::nullopt}, @@ -103,15 +101,15 @@ TEST_F(GrpcObjectMetadataIntegrationTest, ObjectMetadataCRUD) { auto custom = std::chrono::system_clock::now() + std::chrono::hours(24); auto desired_metadata = ObjectMetadata(*patch).set_custom_time(custom); auto updated = - client->UpdateObject(bucket_name, object_name, desired_metadata); + client.UpdateObject(bucket_name, object_name, desired_metadata); ASSERT_STATUS_OK(updated); ASSERT_TRUE(updated->has_custom_time()); ASSERT_EQ(updated->custom_time(), custom); - auto del = client->DeleteObject(bucket_name, object_name); + auto del = client.DeleteObject(bucket_name, object_name); ASSERT_STATUS_OK(del); - get = client->GetObjectMetadata(bucket_name, object_name); + get = client.GetObjectMetadata(bucket_name, object_name); EXPECT_THAT(get, StatusIs(StatusCode::kNotFound)); } @@ -123,32 +121,30 @@ TEST_F(GrpcObjectMetadataIntegrationTest, PatchMetadata) { ASSERT_THAT(bucket_name, Not(IsEmpty())) << "GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME is not set"; - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); - + auto client = MakeIntegrationTestClient(Options{}); auto object_name = MakeRandomObjectName(); // Use the full projection to get consistent behavior out of gRPC and REST. - auto insert = client->InsertObject(bucket_name, object_name, LoremIpsum(), - IfGenerationMatch(0), Projection::Full()); + auto insert = client.InsertObject(bucket_name, object_name, LoremIpsum(), + IfGenerationMatch(0), Projection::Full()); ASSERT_STATUS_OK(insert); ScheduleForDelete(*insert); - auto patch = client->PatchObject(bucket_name, object_name, - ObjectMetadataPatchBuilder{} - .SetMetadata("test-key0", "v0") - .SetMetadata("test-key1", "v1") - .SetMetadata("test-key2", "v2")); + auto patch = client.PatchObject(bucket_name, object_name, + ObjectMetadataPatchBuilder{} + .SetMetadata("test-key0", "v0") + .SetMetadata("test-key1", "v1") + .SetMetadata("test-key2", "v2")); ASSERT_STATUS_OK(patch); EXPECT_THAT(patch->metadata(), AllOf(Contains(Pair("test-key0", "v0")), Contains(Pair("test-key1", "v1")), Contains(Pair("test-key2", "v2")))); - patch = client->PatchObject(bucket_name, object_name, - ObjectMetadataPatchBuilder{} - .SetMetadata("test-key0", "new-v0") - .ResetMetadata("test-key1") - .SetMetadata("test-key3", "v3")); + patch = client.PatchObject(bucket_name, object_name, + ObjectMetadataPatchBuilder{} + .SetMetadata("test-key0", "new-v0") + .ResetMetadata("test-key1") + .SetMetadata("test-key3", "v3")); ASSERT_STATUS_OK(patch); EXPECT_THAT(patch->metadata(), AllOf(Contains(Pair("test-key0", "new-v0")), Not(Contains(Pair("test-key1", _))), diff --git a/google/cloud/storage/tests/grpc_service_account_integration_test.cc b/google/cloud/storage/tests/grpc_service_account_integration_test.cc index 624c5c9edef97..288d7d80c0fe5 100644 --- a/google/cloud/storage/tests/grpc_service_account_integration_test.cc +++ b/google/cloud/storage/tests/grpc_service_account_integration_test.cc @@ -39,10 +39,9 @@ TEST_F(GrpcServiceAccountIntegrationTest, GetServiceAccount) { auto const project_id = GetEnv("GOOGLE_CLOUD_PROJECT").value_or(""); ASSERT_THAT(project_id, Not(IsEmpty())) << "GOOGLE_CLOUD_PROJECT is not set"; - auto client = MakeIntegrationTestClient(); - ASSERT_STATUS_OK(client); + auto client = MakeIntegrationTestClient(Options{}); - auto response = client->GetServiceAccountForProject(project_id); + auto response = client.GetServiceAccountForProject(project_id); ASSERT_STATUS_OK(response); EXPECT_THAT(response->email_address(), Not(IsEmpty())); }