Skip to content

Commit 501806a

Browse files
authored
cleanup(bigquery): add bigquery_rest_testing library (#11062)
1 parent eecc9e5 commit 501806a

7 files changed

Lines changed: 111 additions & 56 deletions

File tree

google/cloud/bigquery/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,30 @@ cc_library(
127127
],
128128
)
129129

130+
load(":bigquery_rest_testing.bzl", "bigquery_rest_testing_hdrs", "bigquery_rest_testing_srcs")
131+
132+
cc_library(
133+
name = "bigquery_rest_testing",
134+
testonly = True,
135+
srcs = bigquery_rest_testing_srcs,
136+
hdrs = bigquery_rest_testing_hdrs,
137+
visibility = [":__subpackages__"],
138+
deps = [
139+
":google_cloud_cpp_bigquery_rest",
140+
":google_cloud_cpp_bigquery_rest_mocks",
141+
"//:common",
142+
"//google/cloud/testing_util:google_cloud_cpp_testing_private",
143+
"@com_google_googletest//:gtest_main",
144+
],
145+
)
146+
130147
load(":bigquery_rest_unit_tests.bzl", "bigquery_rest_unit_tests")
131148

132149
[cc_test(
133150
name = test.replace("/", "_").replace(".cc", ""),
134151
srcs = [test],
135152
deps = [
153+
":bigquery_rest_testing",
136154
":google_cloud_cpp_bigquery_rest",
137155
":google_cloud_cpp_bigquery_rest_mocks",
138156
"//google/cloud/testing_util:google_cloud_cpp_testing_private",

google/cloud/bigquery/bigquery_rest.cmake

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ add_library(google_cloud_cpp_bigquery_rest_mocks INTERFACE)
7070
target_sources(
7171
google_cloud_cpp_bigquery_rest_mocks
7272
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/mocks/mock_job_connection.h
73-
${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/mocks/mock_job_rest_stub.h)
73+
)
7474
target_link_libraries(
7575
google_cloud_cpp_bigquery_rest_mocks
7676
INTERFACE google-cloud-cpp::experimental-bigquery_rest GTest::gmock_main
@@ -102,6 +102,28 @@ function (bigquery_rest_define_tests)
102102
# the GTest::gmock target, and the target names are also weird.
103103
find_package(GTest CONFIG REQUIRED)
104104

105+
add_library(bigquery_rest_testing INTERFACE)
106+
target_sources(
107+
bigquery_rest_testing
108+
INTERFACE
109+
${CMAKE_CURRENT_SOURCE_DIR}/v2/minimal/testing/mock_job_rest_stub.h)
110+
target_link_libraries(
111+
bigquery_rest_testing
112+
INTERFACE google_cloud_cpp_testing
113+
google-cloud-cpp::experimental-bigquery_rest_mocks
114+
google-cloud-cpp::experimental-bigquery_rest
115+
GTest::gmock_main
116+
GTest::gmock
117+
GTest::gtest)
118+
target_include_directories(
119+
bigquery_rest_testing
120+
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
121+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
122+
$<INSTALL_INTERFACE:include>)
123+
target_compile_options(bigquery_rest_testing
124+
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
125+
create_bazel_config(bigquery_rest_testing YEAR "2023")
126+
105127
set(bigquery_rest_unit_tests
106128
# cmake-format: sort
107129
v2/minimal/internal/bigquery_http_response_test.cc
@@ -127,7 +149,8 @@ function (bigquery_rest_define_tests)
127149
google_cloud_cpp_add_executable(target "bigquery" "${fname}")
128150
target_link_libraries(
129151
${target}
130-
PRIVATE google_cloud_cpp_testing
152+
PRIVATE bigquery_rest_testing
153+
google_cloud_cpp_testing
131154
google-cloud-cpp::experimental-bigquery_rest
132155
google-cloud-cpp::experimental-bigquery_rest_mocks
133156
GTest::gmock_main
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed
16+
17+
"""Automatically generated source lists for bigquery_rest_testing - DO NOT EDIT."""
18+
19+
bigquery_rest_testing_hdrs = [
20+
"v2/minimal/testing/mock_job_rest_stub.h",
21+
]
22+
23+
bigquery_rest_testing_srcs = [
24+
]

google/cloud/bigquery/google_cloud_cpp_bigquery_rest_mocks.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
google_cloud_cpp_bigquery_rest_mocks_hdrs = [
2020
"v2/minimal/mocks/mock_job_connection.h",
21-
"v2/minimal/mocks/mock_job_rest_stub.h",
2221
]
2322

2423
google_cloud_cpp_bigquery_rest_mocks_srcs = [

google/cloud/bigquery/v2/minimal/internal/job_connection_test.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "google/cloud/bigquery/v2/minimal/internal/job_client.h"
1717
#include "google/cloud/bigquery/v2/minimal/internal/job_rest_connection_impl.h"
1818
#include "google/cloud/bigquery/v2/minimal/internal/job_rest_stub.h"
19-
#include "google/cloud/bigquery/v2/minimal/mocks/mock_job_rest_stub.h"
19+
#include "google/cloud/bigquery/v2/minimal/testing/mock_job_rest_stub.h"
2020
#include "google/cloud/common_options.h"
2121
#include "google/cloud/internal/make_status.h"
2222
#include "google/cloud/internal/rest_response.h"
@@ -28,6 +28,7 @@ namespace cloud {
2828
namespace bigquery_v2_minimal_internal {
2929
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3030

31+
using ::google::cloud::bigquery_v2_minimal_testing::MockBigQueryJobRestStub;
3132
using ::google::cloud::testing_util::StatusIs;
3233
using ::testing::AtLeast;
3334
using ::testing::HasSubstr;
@@ -99,7 +100,7 @@ TEST(JobConnectionTest, GetJobSuccess) {
99100
}
100101

101102
// Verify that permanent errors are reported immediately.
102-
TEST(GoldenThingAdminConnectionTest, GetJobPermanentError) {
103+
TEST(JobConnectionTest, GetJobPermanentError) {
103104
auto mock = std::make_shared<MockBigQueryJobRestStub>();
104105
EXPECT_CALL(*mock, GetJob)
105106
.WillOnce(
@@ -112,7 +113,7 @@ TEST(GoldenThingAdminConnectionTest, GetJobPermanentError) {
112113
}
113114

114115
// Verify that too many transients errors are reported correctly.
115-
TEST(GoldenThingAdminConnectionTest, GetJobTooManyTransients) {
116+
TEST(JobConnectionTest, GetJobTooManyTransients) {
116117
auto mock = std::make_shared<MockBigQueryJobRestStub>();
117118
EXPECT_CALL(*mock, GetJob)
118119
.Times(AtLeast(2))

google/cloud/bigquery/v2/minimal/mocks/mock_job_rest_stub.h

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_TESTING_MOCK_JOB_REST_STUB_H
16+
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_TESTING_MOCK_JOB_REST_STUB_H
17+
18+
#include "google/cloud/bigquery/v2/minimal/internal/job_rest_stub.h"
19+
#include <gmock/gmock.h>
20+
21+
namespace google {
22+
namespace cloud {
23+
namespace bigquery_v2_minimal_testing {
24+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
25+
26+
class MockBigQueryJobRestStub
27+
: public bigquery_v2_minimal_internal::BigQueryJobRestStub {
28+
public:
29+
MOCK_METHOD(StatusOr<bigquery_v2_minimal_internal::GetJobResponse>, GetJob,
30+
(rest_internal::RestContext & rest_context,
31+
bigquery_v2_minimal_internal::GetJobRequest const& request),
32+
(override));
33+
};
34+
35+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
36+
} // namespace bigquery_v2_minimal_testing
37+
} // namespace cloud
38+
} // namespace google
39+
40+
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_TESTING_MOCK_JOB_REST_STUB_H

0 commit comments

Comments
 (0)