Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(storage): support testing with alternative endpoints #14502

Merged
Show file tree
Hide file tree
Changes from 2 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
37 changes: 26 additions & 11 deletions google/cloud/storage/testing/storage_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,19 @@ namespace storage {
namespace testing {
namespace {

using ::google::cloud::internal::GetEnv;

absl::optional<std::string> 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");
}

Expand All @@ -61,12 +59,29 @@ StorageIntegrationTest::~StorageIntegrationTest() {
}
}

google::cloud::Options StorageIntegrationTest::MakeTestOptions(
google::cloud::Options opts) {
coryan marked this conversation as resolved.
Show resolved Hide resolved
auto fallback = Options{}
.set<RetryPolicyOption>(TestRetryPolicy())
.set<BackoffPolicyOption>(TestBackoffPolicy());
if (auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_TEST_GRPC_ENDPOINT")) {
fallback.set<EndpointOption>(*v);
}
if (auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_TEST_JSON_ENDPOINT")) {
fallback.set<RestEndpointOption>(*v);
}
if (auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_TEST_AUTHORITY")) {
fallback.set<AuthorityOption>(*v);
}
if (auto v = GetEnv("GOOGLE_CLOUD_CPP_STORAGE_TEST_TARGET_API_VERSION")) {
fallback.set<google::cloud::storage::internal::TargetApiVersionOption>(*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<RetryPolicyOption>(TestRetryPolicy())
.set<BackoffPolicyOption>(TestBackoffPolicy()));
opts = MakeTestOptions(std::move(opts));
#if GOOGLE_CLOUD_CPP_STORAGE_HAVE_GRPC
if (UseGrpcForMedia() || UseGrpcForMetadata()) {
return storage_experimental::DefaultGrpcClient(std::move(opts));
Expand Down
8 changes: 8 additions & 0 deletions google/cloud/storage/testing/storage_integration_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ 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 = {});
coryan marked this conversation as resolved.
Show resolved Hide resolved

/**
* Return a client suitable for most integration tests.
*
Expand Down
Loading