From 2e015c4427a53bc5029540a47efa75e73894957d Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Wed, 17 Jul 2024 13:40:40 +0000 Subject: [PATCH 1/3] test(storage): support testing with alternative endpoints --- .../testing/storage_integration_test.cc | 37 +++++++++++++------ .../testing/storage_integration_test.h | 7 ++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/google/cloud/storage/testing/storage_integration_test.cc b/google/cloud/storage/testing/storage_integration_test.cc index f0fa730515999..24250916a547d 100644 --- a/google/cloud/storage/testing/storage_integration_test.cc +++ b/google/cloud/storage/testing/storage_integration_test.cc @@ -29,21 +29,19 @@ namespace storage { namespace testing { namespace { +using ::google::cloud::internal::GetEnv; + absl::optional EmulatorEndpoint() { - return google::cloud::internal::GetEnv("CLOUD_STORAGE_EMULATOR_ENDPOINT"); + return GetEnv("CLOUD_STORAGE_EMULATOR_ENDPOINT"); } bool UseGrpcForMetadata() { - auto v = - google::cloud::internal::GetEnv("GOOGLE_CLOUD_CPP_STORAGE_GRPC_CONFIG") - .value_or(""); + auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_GRPC_CONFIG").value_or(""); return absl::StrContains(v, "metadata"); } bool UseGrpcForMedia() { - auto v = - google::cloud::internal::GetEnv("GOOGLE_CLOUD_CPP_STORAGE_GRPC_CONFIG") - .value_or(""); + auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_GRPC_CONFIG").value_or(""); return absl::StrContains(v, "media"); } @@ -61,12 +59,29 @@ StorageIntegrationTest::~StorageIntegrationTest() { } } +google::cloud::Options StorageIntegrationTest::MakeTestOptions( + google::cloud::Options opts) { + auto fallback = Options{} + .set(TestRetryPolicy()) + .set(TestBackoffPolicy()); + if (auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_TEST_GRPC_ENDPOINT")) { + fallback.set(*v); + } + if (auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_TEST_JSON_ENDPOINT")) { + fallback.set(*v); + } + if (auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_TEST_AUTHORITY")) { + fallback.set(*v); + } + if (auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_TEST_TARGET_API_VERSION")) { + fallback.set(*v); + } + return google::cloud::internal::MergeOptions(std::move(opts), fallback); +} + google::cloud::storage::Client StorageIntegrationTest::MakeIntegrationTestClient(google::cloud::Options opts) { - opts = google::cloud::internal::MergeOptions( - std::move(opts), Options{} - .set(TestRetryPolicy()) - .set(TestBackoffPolicy())); + opts = MakeTestOptions(std::move(opts)); #if GOOGLE_CLOUD_CPP_STORAGE_HAVE_GRPC if (UseGrpcForMedia() || UseGrpcForMetadata()) { return storage_experimental::DefaultGrpcClient(std::move(opts)); diff --git a/google/cloud/storage/testing/storage_integration_test.h b/google/cloud/storage/testing/storage_integration_test.h index ee98ff088095e..8f401cbd8b515 100644 --- a/google/cloud/storage/testing/storage_integration_test.h +++ b/google/cloud/storage/testing/storage_integration_test.h @@ -39,6 +39,13 @@ class StorageIntegrationTest protected: ~StorageIntegrationTest() override; + /** + * Returns the recommended options to run integration tests. + * + * Most tests should use these options or call `MakeIntegrationTestClient()`. + */ + static google::cloud::Options MakeTestOptions(google::cloud::Options opts = {}); + /** * Return a client suitable for most integration tests. * From 952e89e3fa8623f9b489d975c69ba13c46ba83b3 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Fri, 19 Jul 2024 14:32:54 +0000 Subject: [PATCH 2/3] Fix formatting --- google/cloud/storage/testing/storage_integration_test.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/google/cloud/storage/testing/storage_integration_test.h b/google/cloud/storage/testing/storage_integration_test.h index 8f401cbd8b515..ad9aee2f86320 100644 --- a/google/cloud/storage/testing/storage_integration_test.h +++ b/google/cloud/storage/testing/storage_integration_test.h @@ -41,10 +41,11 @@ class StorageIntegrationTest /** * Returns the recommended options to run integration tests. - * + * * Most tests should use these options or call `MakeIntegrationTestClient()`. */ - static google::cloud::Options MakeTestOptions(google::cloud::Options opts = {}); + static google::cloud::Options MakeTestOptions( + google::cloud::Options opts = {}); /** * Return a client suitable for most integration tests. From 8157593ba27eda45250d4984de32be6fe481824b Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Sat, 20 Jul 2024 13:38:25 +0000 Subject: [PATCH 3/3] Address review comments --- google/cloud/storage/testing/storage_integration_test.cc | 5 ++--- google/cloud/storage/testing/storage_integration_test.h | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/google/cloud/storage/testing/storage_integration_test.cc b/google/cloud/storage/testing/storage_integration_test.cc index 24250916a547d..c96f5ca2bf00b 100644 --- a/google/cloud/storage/testing/storage_integration_test.cc +++ b/google/cloud/storage/testing/storage_integration_test.cc @@ -59,8 +59,7 @@ StorageIntegrationTest::~StorageIntegrationTest() { } } -google::cloud::Options StorageIntegrationTest::MakeTestOptions( - google::cloud::Options opts) { +Options StorageIntegrationTest::MakeTestOptions(Options opts) { auto fallback = Options{} .set(TestRetryPolicy()) .set(TestBackoffPolicy()); @@ -80,7 +79,7 @@ google::cloud::Options StorageIntegrationTest::MakeTestOptions( } google::cloud::storage::Client -StorageIntegrationTest::MakeIntegrationTestClient(google::cloud::Options opts) { +StorageIntegrationTest::MakeIntegrationTestClient(Options opts) { opts = MakeTestOptions(std::move(opts)); #if GOOGLE_CLOUD_CPP_STORAGE_HAVE_GRPC if (UseGrpcForMedia() || UseGrpcForMetadata()) { diff --git a/google/cloud/storage/testing/storage_integration_test.h b/google/cloud/storage/testing/storage_integration_test.h index ad9aee2f86320..6d6cf63967e60 100644 --- a/google/cloud/storage/testing/storage_integration_test.h +++ b/google/cloud/storage/testing/storage_integration_test.h @@ -44,8 +44,7 @@ class StorageIntegrationTest * * Most tests should use these options or call `MakeIntegrationTestClient()`. */ - static google::cloud::Options MakeTestOptions( - google::cloud::Options opts = {}); + static Options MakeTestOptions(Options opts = {}); /** * Return a client suitable for most integration tests. @@ -55,7 +54,7 @@ class StorageIntegrationTest * configured. */ static google::cloud::storage::Client MakeIntegrationTestClient( - google::cloud::Options opts = {}); + Options opts = {}); /** * Return a client with retry policies suitable for CreateBucket() class.