Skip to content

Commit 4535334

Browse files
authored
impl(bigquery): Logging decorator cleanup (contd) - Adds DebugString() member functions to GetJobRequest and ListJobsRequest (#11141)
1 parent 2da7476 commit 4535334

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "google/cloud/bigquery/v2/minimal/internal/job_request.h"
1616
#include "google/cloud/common_options.h"
1717
#include "google/cloud/internal/absl_str_cat_quiet.h"
18+
#include "google/cloud/internal/debug_string.h"
1819
#include "google/cloud/internal/format_time_point.h"
1920
#include "google/cloud/internal/make_status.h"
2021
#include "google/cloud/status.h"
@@ -70,6 +71,32 @@ StateFilter StateFilter::Done() {
7071
return state_filter;
7172
}
7273

74+
std::string GetJobRequest::DebugString(TracingOptions const& options) const {
75+
std::string out;
76+
auto const* delim = options.single_line_mode() ? " " : "\n";
77+
absl::StrAppend(&out, "GetJobRequest{", delim,
78+
"project_id=", internal::DebugString(project_id_, options),
79+
delim, "job_id=", internal::DebugString(job_id_, options),
80+
delim, internal::DebugString(location_, options), delim, "}");
81+
return out;
82+
}
83+
84+
std::string ListJobsRequest::DebugString(TracingOptions const& options) const {
85+
std::string out;
86+
auto const* delim = options.single_line_mode() ? " " : "\n";
87+
auto const* all_users = all_users_ ? "true" : "false";
88+
absl::StrAppend(
89+
&out, "ListJobsRequest{", delim,
90+
"project_id=", internal::DebugString(project_id_, options), delim,
91+
", all_users=", all_users, delim, ", max_results=", max_results_, delim,
92+
", page_token=", internal::DebugString(page_token_, options), delim,
93+
", projection=", internal::DebugString(projection_.value, options), delim,
94+
", state_filter=", internal::DebugString(state_filter_.value, options),
95+
delim, ", parent_job_id=", internal::DebugString(parent_job_id_, options),
96+
delim, "}");
97+
return out;
98+
}
99+
73100
ListJobsRequest::ListJobsRequest(std::string project_id)
74101
: project_id_(std::move(project_id)),
75102
all_users_(false),

google/cloud/bigquery/v2/minimal/internal/job_request.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "google/cloud/internal/rest_request.h"
1919
#include "google/cloud/options.h"
2020
#include "google/cloud/status_or.h"
21+
#include "google/cloud/tracing_options.h"
2122
#include "google/cloud/version.h"
2223
#include <chrono>
2324
#include <ostream>
@@ -63,6 +64,8 @@ class GetJobRequest {
6364
return std::move(set_location(std::move(location)));
6465
}
6566

67+
std::string DebugString(TracingOptions const& options) const;
68+
6669
private:
6770
std::string project_id_;
6871
std::string job_id_;
@@ -179,6 +182,8 @@ class ListJobsRequest {
179182
return std::move(set_parent_job_id(std::move(parent_job_id)));
180183
}
181184

185+
std::string DebugString(TracingOptions const& options) const;
186+
182187
// Members
183188
private:
184189
std::string project_id_;

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,36 @@ TEST(ListJobsRequestTest, EmptyProjectId) {
165165
TEST(ListJobsRequestTest, OutputStream) {
166166
auto const request = GetListJobsRequest();
167167
std::string all_users = request.all_users() ? "true" : "false";
168-
std::string expected = absl::StrCat(
169-
"ListJobsRequest{project_id=", request.project_id(),
170-
", all_users=", all_users, ", max_results=", request.max_results(),
171-
", page_token=", request.page_token(),
172-
", projection=", request.projection().value,
173-
", state_filter=", request.state_filter().value,
174-
", parent_job_id=", request.parent_job_id(), "}");
168+
std::string expected =
169+
"ListJobsRequest{project_id=1, all_users=true, max_results=10"
170+
", page_token=123, projection=FULL, state_filter=RUNNING"
171+
", parent_job_id=1}";
175172
std::ostringstream os;
176173
os << request;
177174
EXPECT_EQ(expected, os.str());
178175
}
179176

177+
TEST(GetJobRequest, DebugString) {
178+
GetJobRequest request("test-project-id", "test-job-id");
179+
request.set_location("test-location");
180+
std::string expected =
181+
"GetJobRequest{ project_id=test-project-id job_id=test-job-id "
182+
"test-location }";
183+
184+
EXPECT_EQ(expected, request.DebugString(TracingOptions{}));
185+
}
186+
187+
TEST(ListJobsRequestTest, DebugString) {
188+
auto const request = GetListJobsRequest();
189+
std::string all_users = request.all_users() ? "true" : "false";
190+
std::string expected =
191+
"ListJobsRequest{ project_id=1 , all_users=true , max_results=10 , "
192+
"page_token=123 , projection=FULL , state_filter=RUNNING , "
193+
"parent_job_id=1 }";
194+
195+
EXPECT_EQ(expected, request.DebugString(TracingOptions{}));
196+
}
197+
180198
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
181199
} // namespace bigquery_v2_minimal_internal
182200
} // namespace cloud

0 commit comments

Comments
 (0)