Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
scotthart committed Jul 11, 2024
1 parent 5aefd69 commit 7397f7c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
4 changes: 1 addition & 3 deletions google/cloud/bigquerycontrol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions google/cloud/bigquerycontrol/integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <google/protobuf/text_format.h>
#include <gmock/gmock.h>
#include <chrono>
#include <thread>
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -99,23 +99,28 @@ TEST_F(BigQueryJobIntegrationTest, JobCRUD) {

google::cloud::bigquery::v2::ListJobsRequest list_request;
list_request.set_project_id(project_id_);
std::vector<bigquery_proto::JobReference> job_refs;
std::vector<std::string> job_ids;
std::vector<bigquery_proto::ListFormatJob> 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_);
get_request.set_job_id(job_id);
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));
}
Expand Down

0 comments on commit 7397f7c

Please sign in to comment.