|
24 | 24 | #include <olp/core/client/OlpClient.h>
|
25 | 25 | #include <olp/core/client/OlpClientFactory.h>
|
26 | 26 | #include <olp/core/client/OlpClientSettingsFactory.h>
|
| 27 | +#include <olp/core/utils/Url.h> |
27 | 28 | #include "generated/api/MetadataApi.h"
|
28 | 29 |
|
29 | 30 | namespace {
|
@@ -125,4 +126,130 @@ TEST_F(MetadataApiTest, GetListVersions) {
|
125 | 126 | }
|
126 | 127 | }
|
127 | 128 |
|
| 129 | +struct TestParameters { |
| 130 | + boost::optional<int64_t> version; |
| 131 | + std::string layer; |
| 132 | + std::string url; |
| 133 | + std::vector<std::string> additional_fields; |
| 134 | + boost::optional<std::string> billing_tag; |
| 135 | + boost::optional<std::string> range; |
| 136 | +}; |
| 137 | + |
| 138 | +class MetadataApiParamTest |
| 139 | + : public MetadataApiTest, |
| 140 | + public testing::WithParamInterface<TestParameters> {}; |
| 141 | + |
| 142 | +TEST_P(MetadataApiParamTest, GetPartitionsStream) { |
| 143 | + using testing::AllOf; |
| 144 | + using testing::Eq; |
| 145 | + using testing::Mock; |
| 146 | + using testing::Return; |
| 147 | + |
| 148 | + const TestParameters test_params = GetParam(); |
| 149 | + |
| 150 | + olp::client::CancellationContext context; |
| 151 | + |
| 152 | + boost::optional<std::uint64_t> received_offset; |
| 153 | + std::string received_stream_data; |
| 154 | + |
| 155 | + auto data_callback = [&](const std::uint8_t* data, std::uint64_t offset, |
| 156 | + std::size_t length) mutable { |
| 157 | + received_stream_data.assign(reinterpret_cast<const char*>(data), length); |
| 158 | + received_offset = offset; |
| 159 | + }; |
| 160 | + |
| 161 | + const std::string ref_stream_data{"reference stream data"}; |
| 162 | + const std::uint64_t offset{7}; |
| 163 | + |
| 164 | + const auto range_header = [&]() -> boost::optional<olp::http::Header> { |
| 165 | + if (test_params.range.has_value()) { |
| 166 | + return olp::http::Header{"Range", test_params.range.value()}; |
| 167 | + } |
| 168 | + return boost::none; |
| 169 | + }(); |
| 170 | + |
| 171 | + EXPECT_CALL(*network_mock_, Send(AllOf(IsGetRequest(test_params.url), |
| 172 | + HeadersContainOptional(range_header)), |
| 173 | + _, _, _, _)) |
| 174 | + .WillOnce(ReturnHttpResponseWithDataCallback( |
| 175 | + olp::http::NetworkResponse().WithStatus( |
| 176 | + olp::http::HttpStatusCode::OK), |
| 177 | + ref_stream_data, offset)); |
| 178 | + |
| 179 | + client::HttpResponse response = |
| 180 | + olp::dataservice::read::MetadataApi::GetPartitionsStream( |
| 181 | + *client_, test_params.layer, test_params.version, |
| 182 | + test_params.additional_fields, test_params.range, |
| 183 | + test_params.billing_tag, data_callback, context); |
| 184 | + |
| 185 | + EXPECT_EQ(response.GetStatus(), http::HttpStatusCode::OK); |
| 186 | + EXPECT_STREQ(ref_stream_data.c_str(), received_stream_data.c_str()); |
| 187 | + EXPECT_TRUE(received_offset.has_value()); |
| 188 | + EXPECT_EQ(received_offset.value_or(0), offset); |
| 189 | +} |
| 190 | + |
| 191 | +std::vector<TestParameters> GetPartitionsStreamParams() { |
| 192 | + std::vector<TestParameters> config; |
| 193 | + TestParameters params; |
| 194 | + |
| 195 | + params.billing_tag = boost::none; |
| 196 | + params.layer = "testLayer"; |
| 197 | + params.range = boost::none; |
| 198 | + params.version = boost::none; |
| 199 | + params.url = std::string(kNodeBaseUrl) + R"(/layers/)" + params.layer + |
| 200 | + R"(/partitions)"; |
| 201 | + config.emplace_back(params); |
| 202 | + |
| 203 | + params.billing_tag = boost::none; |
| 204 | + params.layer = "testLayer"; |
| 205 | + params.range = boost::none; |
| 206 | + params.version = kStartVersion; |
| 207 | + params.url = std::string(kNodeBaseUrl) + R"(/layers/)" + params.layer + |
| 208 | + R"(/partitions?version=)" + |
| 209 | + std::to_string(params.version.value()); |
| 210 | + config.emplace_back(params); |
| 211 | + |
| 212 | + params.billing_tag = boost::none; |
| 213 | + params.layer = "testLayer"; |
| 214 | + params.range = "rangeReferenceValue"; |
| 215 | + params.version = boost::none; |
| 216 | + params.url = std::string(kNodeBaseUrl) + R"(/layers/)" + params.layer + |
| 217 | + R"(/partitions)"; |
| 218 | + config.emplace_back(params); |
| 219 | + |
| 220 | + params.billing_tag = "billingTagValue"; |
| 221 | + params.layer = "testLayer"; |
| 222 | + params.range = "rangeReferenceValue"; |
| 223 | + params.version = boost::none; |
| 224 | + params.url = std::string(kNodeBaseUrl) + R"(/layers/)" + params.layer + |
| 225 | + R"(/partitions?billingTag=)" + params.billing_tag.value(); |
| 226 | + config.emplace_back(params); |
| 227 | + |
| 228 | + params.additional_fields = {"checksum", "compressedDataSize"}; |
| 229 | + params.billing_tag = boost::none; |
| 230 | + params.layer = "testLayer"; |
| 231 | + params.range = boost::none; |
| 232 | + params.version = boost::none; |
| 233 | + params.url = std::string(kNodeBaseUrl) + R"(/layers/)" + params.layer + |
| 234 | + R"(/partitions?additionalFields=)" + |
| 235 | + olp::utils::Url::Encode(R"(checksum,compressedDataSize)"); |
| 236 | + config.emplace_back(params); |
| 237 | + |
| 238 | + params.additional_fields = {"compressedDataSize"}; |
| 239 | + params.billing_tag = boost::none; |
| 240 | + params.layer = "testLayer"; |
| 241 | + params.range = boost::none; |
| 242 | + params.version = kEndVersion; |
| 243 | + params.url = std::string(kNodeBaseUrl) + R"(/layers/)" + params.layer + |
| 244 | + R"(/partitions?additionalFields=)" + |
| 245 | + olp::utils::Url::Encode(R"(compressedDataSize)") + |
| 246 | + R"(&version=)" + std::to_string(params.version.value()); |
| 247 | + config.emplace_back(params); |
| 248 | + |
| 249 | + return config; |
| 250 | +} |
| 251 | + |
| 252 | +INSTANTIATE_TEST_SUITE_P(, MetadataApiParamTest, |
| 253 | + testing::ValuesIn(GetPartitionsStreamParams())); |
| 254 | + |
128 | 255 | } // namespace
|
0 commit comments