Skip to content

Commit

Permalink
chore: Using string_view instead of const string reference (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiakiteaneo authored Oct 7, 2024
2 parents 852a9b1 + 26e6cb7 commit b63f015
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ bool initialize_protocol_endpoint(const common::options::ControlPlane &controlPl
* @param userPrivatePem The client key for mTLS
* @return a pointer to a certificate provider interface
*/
std::shared_ptr<CertificateProviderInterface> create_certificate_provider(const std::string &rootCertificate,
const std::string &userPublicPem,
const std::string &userPrivatePem) {
std::shared_ptr<CertificateProviderInterface> create_certificate_provider(absl::string_view rootCertificate,
absl::string_view userPublicPem,
absl::string_view userPrivatePem) {
if (rootCertificate.empty()) {
return std::make_shared<StaticDataCertificateProvider>(
std::vector<IdentityKeyCertPair>{IdentityKeyCertPair{userPrivatePem, userPublicPem}});
std::vector<IdentityKeyCertPair>{IdentityKeyCertPair{userPrivatePem.data(), userPublicPem.data()}});
} else if (userPrivatePem.empty() || userPublicPem.empty()) {
return std::make_shared<StaticDataCertificateProvider>(rootCertificate);
return std::make_shared<StaticDataCertificateProvider>(rootCertificate.data());
} else {
return std::make_shared<StaticDataCertificateProvider>(
rootCertificate, std::vector<IdentityKeyCertPair>{IdentityKeyCertPair{userPrivatePem, userPublicPem}});
rootCertificate.data(),
std::vector<IdentityKeyCertPair>{IdentityKeyCertPair{userPrivatePem.data(), userPublicPem.data()}});
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/cpp/ArmoniK.Api.Tests/header/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ void init(std::shared_ptr<grpc::Channel> &channel, armonik::api::grpc::v1::TaskO
* @param num_calls the number of call of rpc
* @return
*/
bool rpcCalled(const std::string &service_name, const std::string &rpc_name, int num_calls = 1,
const std::string &endpoint = "http://localhost:4999/calls.json");
bool rpcCalled(absl::string_view service_name, absl::string_view rpc_name, int num_calls = 1,
absl::string_view endpoint = "http://localhost:4999/calls.json");

/**
*
* @param service_name the service name
* @param endpoint the call endpoint
* @return
*/
bool all_rpc_called(const std::string &service_name, const std::vector<std::string> &missings = {},
const std::string &endpoint = "http://localhost:4999/calls.json");
bool all_rpc_called(absl::string_view service_name, const std::vector<std::string> &missings = {},
absl::string_view endpoint = "http://localhost:4999/calls.json");

/**
*
* @param endpoint The reset endpoint
*/
void clean_up(const std::string &endpoint = "http://localhost:4999/reset");
void clean_up(absl::string_view endpoint = "http://localhost:4999/reset");

/**
* A fixture class to reset the RPC calls
Expand Down
23 changes: 11 additions & 12 deletions packages/cpp/ArmoniK.Api.Tests/source/MockTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ size_t WriteCallback(void *ptr, size_t size, size_t num_elt, std::string *data)
return size * num_elt;
}

bool rpcCalled(const std::string &service_name, const std::string &rpc_name, int num_calls,
const std::string &endpoint) {
bool rpcCalled(absl::string_view service_name, absl::string_view rpc_name, int num_calls, absl::string_view endpoint) {

auto curl = curl_easy_init();
std::string read_buffer;
std::cout << endpoint << std::endl;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, endpoint.c_str());
curl_easy_setopt(curl, CURLOPT_URL, endpoint.data());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &read_buffer);

Expand All @@ -43,7 +42,7 @@ bool rpcCalled(const std::string &service_name, const std::string &rpc_name, int

try {
dom::element response_json = parser.parse(read_buffer);
if (response_json[service_name][rpc_name].get_int64() == num_calls) {
if (response_json[service_name.data()][rpc_name.data()].get_int64() == num_calls) {
return true;
}
} catch (const simdjson_error &e) {
Expand All @@ -53,13 +52,13 @@ bool rpcCalled(const std::string &service_name, const std::string &rpc_name, int
return false;
}

bool all_rpc_called(const std::string &service_name, const std::vector<std::string> &missings,
const std::string &endpoint) {
bool all_rpc_called(absl::string_view service_name, const std::vector<std::string> &missings,
absl::string_view endpoint) {
auto curl = curl_easy_init();
std::string read_buffer;
std::cout << endpoint << std::endl;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, endpoint.c_str());
curl_easy_setopt(curl, CURLOPT_URL, endpoint.data());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &read_buffer);

Expand All @@ -76,11 +75,11 @@ bool all_rpc_called(const std::string &service_name, const std::vector<std::stri
try {
dom::element response_json = parser.parse(read_buffer);

dom::array rpcs = response_json[service_name];
dom::array rpcs = response_json[service_name.data()];

std::vector<std::string> missing_rpcs;
for (auto rpc_name : response_json[service_name].get_array()) {
if (response_json[service_name][rpc_name].get_int64() == 0) {
for (auto rpc_name : response_json[service_name.data()].get_array()) {
if (response_json[service_name.data()][rpc_name].get_int64() == 0) {
missing_rpcs.emplace_back(rpc_name.get_string().value().data());
}
}
Expand All @@ -101,11 +100,11 @@ bool all_rpc_called(const std::string &service_name, const std::vector<std::stri
return true;
}

void clean_up(const std::string &endpoint) {
void clean_up(absl::string_view endpoint) {
auto curl = curl_easy_init();
std::string read_buffer;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, endpoint.c_str());
curl_easy_setopt(curl, CURLOPT_URL, endpoint.data());
curl_easy_setopt(curl, CURLOPT_POST, 1L);
auto res = curl_easy_perform(curl);
if (res != CURLE_OK) {
Expand Down

0 comments on commit b63f015

Please sign in to comment.