Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
coryan committed Aug 4, 2023
1 parent bdbcca5 commit aa28782
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions google/cloud/storage/client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "google/cloud/internal/getenv.h"
#include "google/cloud/opentelemetry_options.h"
#include "google/cloud/testing_util/mock_backoff_policy.h"
#include "google/cloud/testing_util/opentelemetry_matchers.h"
#include "google/cloud/testing_util/scoped_environment.h"
#include <gmock/gmock.h>
#include <chrono>
Expand Down Expand Up @@ -221,10 +222,11 @@ TEST_F(ClientTest, LoggingDecoratorsRestClient) {
"RetryClient"));
}

/// @test Verify the constructor creates the right set of RawClient decorations.
TEST_F(ClientTest, FullStack) {
// Reset environment variables. We want the `Options` parameter to control the
// structure of the stack.
#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY
using ::google::cloud::testing_util::DisableTracing;
using ::google::cloud::testing_util::EnableTracing;

TEST_F(ClientTest, OTelEnableTracing) {
ScopedEnvironment logging("CLOUD_STORAGE_ENABLE_TRACING", absl::nullopt);
ScopedEnvironment legacy("GOOGLE_CLOUD_CPP_STORAGE_USE_LEGACY_HTTP",
absl::nullopt);
Expand All @@ -235,24 +237,39 @@ TEST_F(ClientTest, FullStack) {
.set<UnifiedCredentialsOption>(MakeInsecureCredentials())
.set<internal::UseRestClientOption>(true)
.set<TracingComponentsOption>({"raw-client"});
#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY
options.set<experimental::OpenTelemetryTracingOption>(true);
#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY

auto tested = Client(options);
auto tested = Client(EnableTracing(std::move(options)));
auto const impl = ClientImplDetails::GetRawClient(tested);
ASSERT_THAT(impl, NotNull());
#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY

EXPECT_THAT(impl->InspectStackStructure(),
ElementsAre("RestClient", "LoggingClient", "GenericStubAdapter",
"RetryClient", "TracingClient"));
#else
}

TEST_F(ClientTest, OTelDisableTracing) {
ScopedEnvironment logging("CLOUD_STORAGE_ENABLE_TRACING", absl::nullopt);
ScopedEnvironment legacy("GOOGLE_CLOUD_CPP_STORAGE_USE_LEGACY_HTTP",
absl::nullopt);

// Create a client. Use the anonymous credentials because on the CI
// environment there may not be other credentials configured.
auto options = Options{}
.set<UnifiedCredentialsOption>(MakeInsecureCredentials())
.set<internal::UseRestClientOption>(true)
.set<TracingComponentsOption>({"raw-client"});

auto tested = Client(DisableTracing(std::move(options)));
auto const impl = ClientImplDetails::GetRawClient(tested);
ASSERT_THAT(impl, NotNull());

EXPECT_THAT(impl->InspectStackStructure(),
ElementsAre("RestClient", "LoggingClient", "GenericStubAdapter",
"RetryClient"));
#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY
}

#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY

#include "google/cloud/internal/disable_deprecation_warnings.inc"

TEST_F(ClientTest, DeprecatedButNotDecommissioned) {
Expand Down

0 comments on commit aa28782

Please sign in to comment.