Skip to content

Commit d088091

Browse files
authored
Fix path duplication with catalog provider (#1326)
Fix path duplication when using catalog endpoint provider: as it's base url being set in GetStaticUrl method of OlpClient there is no need to add path later in GetCatalog. Relates-To: OLPEDGE-2730 Signed-off-by: Yevhenii Dudnyk <[email protected]>
1 parent 363244f commit d088091

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

olp-cpp-sdk-dataservice-read/src/generated/api/ConfigApi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ ConfigApi::CatalogResponse ConfigApi::GetCatalog(
4343
if (billing_tag) {
4444
query_params.insert(std::make_pair("billingTag", *billing_tag));
4545
}
46-
std::string catalog_uri = "/catalogs/" + catalog_hrn;
46+
auto catalog_uri =
47+
catalog_hrn.empty() ? std::string() : "/catalogs/" + catalog_hrn;
4748

4849
client::HttpResponse response = client.CallApi(
4950
std::move(catalog_uri), "GET", std::move(query_params),

olp-cpp-sdk-dataservice-read/src/repositories/CatalogRepository.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ CatalogResponse CatalogRepository::GetCatalog(
5454
const CatalogRequest& request, client::CancellationContext context) {
5555
const auto request_key = request.CreateKey();
5656
const auto fetch_options = request.GetFetchOption();
57-
const auto catalog_str = catalog_.ToCatalogHRNString();
57+
const auto catalog_str =
58+
settings_.api_lookup_settings.catalog_endpoint_provider
59+
? std::string()
60+
: catalog_.ToCatalogHRNString();
5861

5962
repository::CatalogCacheRepository repository(
6063
catalog_, settings_.cache, settings_.default_cache_expiration);

tests/integration/olp-cpp-sdk-dataservice-read/CatalogClientCacheTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ constexpr auto kClientTestCacheDir = "\\catalog_client_test\\cache";
4343
constexpr auto kClientTestDir = "/catalog_client_test";
4444
constexpr auto kClientTestCacheDir = "/cata.log_client_test/cache";
4545
#endif
46+
constexpr auto kWaitTimeout = std::chrono::seconds(3);
4647

4748
class CatalogClientCacheTest : public integration::CatalogClientTestBase {
4849
protected:
@@ -166,6 +167,27 @@ TEST_P(CatalogClientCacheTest, GetCatalog) {
166167
catalog_response.GetResult().GetName());
167168
}
168169

170+
TEST_P(CatalogClientCacheTest, GetCatalogUsingCatalogEndpointProvider) {
171+
olp::client::HRN hrn(GetTestCatalog());
172+
173+
std::string provider_url =
174+
"https://api-lookup.data.api.platform.here.com/lookup/v1";
175+
EXPECT_CALL(*network_mock_, Send(IsGetRequest(provider_url + "/catalogs/" +
176+
hrn.ToCatalogHRNString()),
177+
_, _, _, _))
178+
.WillOnce(::testing::Return(
179+
olp::http::SendOutcome(olp::http::ErrorCode::SUCCESS)));
180+
181+
settings_.api_lookup_settings.catalog_endpoint_provider =
182+
[&provider_url](const olp::client::HRN&) { return provider_url; };
183+
auto catalog_client = std::make_unique<read::CatalogClient>(hrn, settings_);
184+
185+
auto request = read::CatalogRequest();
186+
auto future = catalog_client->GetCatalog(request).GetFuture();
187+
ASSERT_NE(future.wait_for(kWaitTimeout), std::future_status::timeout);
188+
future.get();
189+
}
190+
169191
INSTANTIATE_TEST_SUITE_P(, CatalogClientCacheTest,
170192
::testing::Values(integration::CacheType::IN_MEMORY,
171193
integration::CacheType::DISK,

0 commit comments

Comments
 (0)