diff --git a/google/cloud/bigquerycontrol/CMakeLists.txt b/google/cloud/bigquerycontrol/CMakeLists.txt index d6dcde2722126..dfb1290af6914 100644 --- a/google/cloud/bigquerycontrol/CMakeLists.txt +++ b/google/cloud/bigquerycontrol/CMakeLists.txt @@ -197,9 +197,7 @@ if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS) PROPERTIES LABELS "integration-test;quickstart") endif () -if (BUILD_TESTING) - add_subdirectory(integration_tests) -endif () +add_subdirectory(integration_tests) # google-cloud-cpp::experimental-bigquerycontrol must be defined before we can # add the samples. diff --git a/google/cloud/bigquerycontrol/integration_tests/CMakeLists.txt b/google/cloud/bigquerycontrol/integration_tests/CMakeLists.txt index 8535bf41af753..98cd6877f72ee 100644 --- a/google/cloud/bigquerycontrol/integration_tests/CMakeLists.txt +++ b/google/cloud/bigquerycontrol/integration_tests/CMakeLists.txt @@ -14,11 +14,11 @@ # limitations under the License. # ~~~ -# The tests require googletest to be installed. Force CMake to use the config -# file for googletest (that is, the CMake file installed by googletest itself), -# because the generic `FindGTest` module does not define the GTest::gmock -# target, and the target names are also weird. -find_package(GTest CONFIG REQUIRED) +if (NOT BUILD_TESTING) + return() +endif () + +include(FindGMockWithTargets) set(bigquerycontrol_integration_tests # cmake-format: sort job_integration_test.cc) diff --git a/google/cloud/bigquerycontrol/integration_tests/job_integration_test.cc b/google/cloud/bigquerycontrol/integration_tests/job_integration_test.cc index 63991b0cfeeb6..1b040a7959c67 100644 --- a/google/cloud/bigquerycontrol/integration_tests/job_integration_test.cc +++ b/google/cloud/bigquerycontrol/integration_tests/job_integration_test.cc @@ -16,6 +16,7 @@ #include "google/cloud/internal/getenv.h" #include "google/cloud/testing_util/integration_test.h" #include "google/cloud/testing_util/status_matchers.h" +#include #include #include #include @@ -33,6 +34,7 @@ using ::testing::Eq; using ::testing::HasSubstr; using ::testing::IsEmpty; using ::testing::Not; +using ::testing::ResultOf; class BigQueryJobIntegrationTest : public ::google::cloud::testing_util::IntegrationTest { @@ -60,19 +62,17 @@ TEST_F(BigQueryJobIntegrationTest, JobCRUD) { auto use_legacy_sql = google::protobuf::BoolValue(); use_legacy_sql.set_value(false); *query.mutable_use_legacy_sql() = use_legacy_sql; + query.set_parameter_mode("NAMED"); // Specify value for named integer parameter: @minimum_year - query.set_parameter_mode("NAMED"); bigquery_proto::QueryParameter minimum_year_param; - minimum_year_param.set_name("minimum_year"); - bigquery_proto::QueryParameterType minimum_year_param_type; - minimum_year_param_type.set_type("INT64"); - *minimum_year_param.mutable_parameter_type() = minimum_year_param_type; - bigquery_proto::QueryParameterValue minimum_year_param_value; - auto year_value = google::protobuf::StringValue(); - year_value.set_value("1970"); - *minimum_year_param_value.mutable_value() = year_value; - *minimum_year_param.mutable_parameter_value() = minimum_year_param_value; + auto constexpr kMinimumYearParam = R"pb( + name: "minimum_year" + parameter_type { type: "INT64" } + parameter_value { value { value: "1970" } } + )pb"; + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( + kMinimumYearParam, &minimum_year_param)); *query.add_query_parameters() = minimum_year_param; bigquery_proto::JobConfiguration config; @@ -99,14 +99,16 @@ TEST_F(BigQueryJobIntegrationTest, JobCRUD) { google::cloud::bigquery::v2::ListJobsRequest list_request; list_request.set_project_id(project_id_); - std::vector job_refs; - std::vector job_ids; + std::vector jobs; for (auto job : client.ListJobs(list_request)) { ASSERT_STATUS_OK(job); - job_refs.push_back(job->job_reference()); - job_ids.push_back(job->job_reference().job_id()); + jobs.push_back(*std::move(job)); } - EXPECT_THAT(job_ids, Contains(job_id)); + EXPECT_THAT( + jobs, + Contains(ResultOf( + "job id", [](auto const& x) { return x.job_reference().job_id(); }, + job_id))); google::cloud::bigquery::v2::GetJobRequest get_request; get_request.set_project_id(project_id_); @@ -114,8 +116,11 @@ TEST_F(BigQueryJobIntegrationTest, JobCRUD) { bool job_complete = false; while (!job_complete) { auto get_result = client.GetJob(get_request); - ASSERT_STATUS_OK(get_result); - EXPECT_THAT(get_result->job_reference().job_id(), Eq(job_id)); + ASSERT_THAT( + get_result, + testing_util::IsOkAndHolds(ResultOf( + "job id", [](auto const& x) { return x.job_reference().job_id(); }, + job_id))); if (get_result->status().state() == "DONE") job_complete = true; std::this_thread::sleep_for(std::chrono::seconds(2)); }