Skip to content

Commit db9c5fb

Browse files
committed
Reduce code coverage problems
1 parent 8d164d7 commit db9c5fb

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

examples/site/testing_pubsub/pubsub_integration_test.cc

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ TEST_F(PubsubIntegrationTest, Basic) {
113113

114114
extern "C" size_t CurlOnWriteData(char* ptr, size_t size, size_t nmemb,
115115
void* userdata) {
116-
auto* buffer = reinterpret_cast<std::string*>(userdata);
117-
buffer->append(ptr, size * nmemb);
116+
reinterpret_cast<std::string*>(userdata)->append(ptr, size * nmemb);
118117
return size * nmemb;
119118
}
120119

@@ -136,10 +135,8 @@ HttpResponse HttpEvent(std::string const& url, std::string const& payload) {
136135
auto get_response_code = [h = easy.get()]() {
137136
long code; // NOLINT(google-runtime-int)
138137
auto e = curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &code);
139-
if (e == CURLE_OK) {
140-
return code;
141-
}
142-
throw std::runtime_error("Cannot get response code");
138+
if (e != CURLE_OK) std::runtime_error("Cannot get response code");
139+
return code;
143140
};
144141

145142
auto headers = CurlHeaders(nullptr, curl_slist_free_all);
@@ -152,18 +149,16 @@ HttpResponse HttpEvent(std::string const& url, std::string const& payload) {
152149
setopt(CURLOPT_URL, url.c_str());
153150
setopt(CURLOPT_POSTFIELDSIZE, payload.size());
154151
setopt(CURLOPT_POSTFIELDS, payload.data());
152+
std::string buffer;
153+
setopt(CURLOPT_WRITEDATA, &buffer);
155154
setopt(CURLOPT_WRITEFUNCTION, &CurlOnWriteData);
156155
add_header("Content-Type: application/cloudevents+json");
157156
add_header("Content-Length: " + std::to_string(payload.size()));
158157
setopt(CURLOPT_HTTPHEADER, headers.get());
159-
std::string buffer;
160-
setopt(CURLOPT_WRITEDATA, &buffer);
161158

162159
auto e = curl_easy_perform(easy.get());
163-
if (e == CURLE_OK) {
164-
return HttpResponse{get_response_code(), std::move(buffer)};
165-
}
166-
return HttpResponse{-1, {}};
160+
if (e != CURLE_OK) throw std::runtime_error("Error in curl_easy_perform");
161+
return HttpResponse{get_response_code(), std::move(buffer)};
167162
}
168163

169164
bool PubsubIntegrationTest::WaitForServerReady(std::string const& url) {

0 commit comments

Comments
 (0)