From 81f1a3a7266c38dd18056f8c4dfd8021773eae09 Mon Sep 17 00:00:00 2001 From: Darren Bolduc Date: Sun, 7 May 2023 22:49:11 -0400 Subject: [PATCH] refactor(bigtable): move test (#11521) --- google/cloud/bigtable/CMakeLists.txt | 1 + .../bigtable/bigtable_client_unit_tests.bzl | 1 + google/cloud/bigtable/data_connection_test.cc | 52 +++++++++++++++++++ .../internal/data_connection_impl_test.cc | 19 ------- 4 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 google/cloud/bigtable/data_connection_test.cc diff --git a/google/cloud/bigtable/CMakeLists.txt b/google/cloud/bigtable/CMakeLists.txt index b6abe693eaab..be5d9a207194 100644 --- a/google/cloud/bigtable/CMakeLists.txt +++ b/google/cloud/bigtable/CMakeLists.txt @@ -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 diff --git a/google/cloud/bigtable/bigtable_client_unit_tests.bzl b/google/cloud/bigtable/bigtable_client_unit_tests.bzl index 90162ffdb400..00d42758ecf1 100644 --- a/google/cloud/bigtable/bigtable_client_unit_tests.bzl +++ b/google/cloud/bigtable/bigtable_client_unit_tests.bzl @@ -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", diff --git a/google/cloud/bigtable/data_connection_test.cc b/google/cloud/bigtable/data_connection_test.cc new file mode 100644 index 000000000000..e79700e27a11 --- /dev/null +++ b/google/cloud/bigtable/data_connection_test.cc @@ -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 +#include + +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("user-supplied") + // Disable channel refreshing, which is not under test. + .set(ms(0)) + // Create the minimum number of stubs. + .set(1)); + auto options = conn->options(); + EXPECT_TRUE(options.has()) + << "Options are not defaulted in MakeDataConnection()"; + EXPECT_EQ(options.get(), "user-supplied") + << "User supplied Options are overridden in MakeDataConnection()"; +} + +} // namespace +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigtable +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigtable/internal/data_connection_impl_test.cc b/google/cloud/bigtable/internal/data_connection_impl_test.cc index f64d167cbe97..9de15ca58241 100644 --- a/google/cloud/bigtable/internal/data_connection_impl_test.cc +++ b/google/cloud/bigtable/internal/data_connection_impl_test.cc @@ -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 #include @@ -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("user-supplied") - // Disable channel refreshing, which is not under test. - .set(ms(0)) - // Create the minimum number of stubs. - .set(1)); - auto options = conn->options(); - EXPECT_TRUE(options.has()) - << "Options are not defaulted in MakeDataConnection()"; - EXPECT_EQ(options.get(), "user-supplied") - << "User supplied Options are overridden in MakeDataConnection()"; -} - } // namespace GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace bigtable_internal