diff --git a/google/cloud/storage/testing/storage_integration_test.cc b/google/cloud/storage/testing/storage_integration_test.cc index f0fa730515999..c96f5ca2bf00b 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,28 @@ StorageIntegrationTest::~StorageIntegrationTest() { } } +Options StorageIntegrationTest::MakeTestOptions(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())); +StorageIntegrationTest::MakeIntegrationTestClient(Options opts) { + 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..6d6cf63967e60 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 Options MakeTestOptions(Options opts = {}); + /** * Return a client suitable for most integration tests. * @@ -47,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.