Skip to content

Commit

Permalink
refactor(bigtable): move test (#11521)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc committed May 8, 2023
1 parent df444d5 commit 81f1a3a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
1 change: 1 addition & 0 deletions google/cloud/bigtable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ if (BUILD_TESTING)
cluster_config_test.cc
column_family_test.cc
data_client_test.cc
data_connection_test.cc
expr_test.cc
filters_test.cc
force_sanitizer_failures_test.cc
Expand Down
1 change: 1 addition & 0 deletions google/cloud/bigtable/bigtable_client_unit_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bigtable_client_unit_tests = [
"cluster_config_test.cc",
"column_family_test.cc",
"data_client_test.cc",
"data_connection_test.cc",
"expr_test.cc",
"filters_test.cc",
"force_sanitizer_failures_test.cc",
Expand Down
52 changes: 52 additions & 0 deletions google/cloud/bigtable/data_connection_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "google/cloud/bigtable/data_connection.h"
#include "google/cloud/bigtable/options.h"
#include "google/cloud/grpc_options.h"
#include "google/cloud/testing_util/scoped_environment.h"
#include <gmock/gmock.h>
#include <chrono>

namespace google {
namespace cloud {
namespace bigtable {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

using ::google::cloud::testing_util::ScopedEnvironment;
using ms = std::chrono::milliseconds;

TEST(MakeDataConnection, DefaultsOptions) {
ScopedEnvironment emulator_host("BIGTABLE_EMULATOR_HOST", "localhost:1");

auto conn = MakeDataConnection(
Options{}
.set<AppProfileIdOption>("user-supplied")
// Disable channel refreshing, which is not under test.
.set<MaxConnectionRefreshOption>(ms(0))
// Create the minimum number of stubs.
.set<GrpcNumChannelsOption>(1));
auto options = conn->options();
EXPECT_TRUE(options.has<DataRetryPolicyOption>())
<< "Options are not defaulted in MakeDataConnection()";
EXPECT_EQ(options.get<AppProfileIdOption>(), "user-supplied")
<< "User supplied Options are overridden in MakeDataConnection()";
}

} // namespace
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace bigtable
} // namespace cloud
} // namespace google
19 changes: 0 additions & 19 deletions google/cloud/bigtable/internal/data_connection_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "google/cloud/grpc_options.h"
#include "google/cloud/internal/async_streaming_read_rpc_impl.h"
#include "google/cloud/testing_util/mock_backoff_policy.h"
#include "google/cloud/testing_util/scoped_environment.h"
#include "google/cloud/testing_util/status_matchers.h"
#include <google/protobuf/text_format.h>
#include <gmock/gmock.h>
Expand Down Expand Up @@ -1549,24 +1548,6 @@ TEST(DataConnectionTest, AsyncReadRowFailure) {
EXPECT_THAT(resp, StatusIs(StatusCode::kPermissionDenied));
}

TEST(MakeDataConnection, DefaultsOptions) {
using ::google::cloud::testing_util::ScopedEnvironment;
ScopedEnvironment emulator_host("BIGTABLE_EMULATOR_HOST", "localhost:1");

auto conn = bigtable::MakeDataConnection(
Options{}
.set<bigtable::AppProfileIdOption>("user-supplied")
// Disable channel refreshing, which is not under test.
.set<bigtable::MaxConnectionRefreshOption>(ms(0))
// Create the minimum number of stubs.
.set<GrpcNumChannelsOption>(1));
auto options = conn->options();
EXPECT_TRUE(options.has<bigtable::DataRetryPolicyOption>())
<< "Options are not defaulted in MakeDataConnection()";
EXPECT_EQ(options.get<bigtable::AppProfileIdOption>(), "user-supplied")
<< "User supplied Options are overridden in MakeDataConnection()";
}

} // namespace
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace bigtable_internal
Expand Down

0 comments on commit 81f1a3a

Please sign in to comment.