Skip to content

Commit 97507b0

Browse files
committed
add basic demo and test for POC
1 parent 4ae2907 commit 97507b0

File tree

4 files changed

+54
-36
lines changed

4 files changed

+54
-36
lines changed

src/iceberg/catalog/rest/rest_catalog.cc

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
// Licensed to the Apache Software Foundation (ASF) under one
2-
// or more contributor license agreements. See the NOTICE file
3-
// distributed with this work for additional information
4-
// regarding copyright ownership. The ASF licenses this file
5-
// to you under the Apache License, Version 2.0 (the
6-
// "License"); you may not use this file except in compliance
7-
// with the License. You may obtain a copy of the License at
8-
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
10-
//
11-
// Unless required by applicable law or agreed to in writing,
12-
// software distributed under the License is distributed on an
13-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
// KIND, either express or implied. See the License for the
15-
// specific language governing permissions and limitations
16-
// under the License.
1+
// In file: iceberg/catalog/rest/rest_catalog.cc
172

183
#include "iceberg/catalog/rest/rest_catalog.h"
194

20-
#include <iostream>
21-
225
#include <cpr/cpr.h>
236

247
namespace iceberg {
@@ -27,26 +10,12 @@ namespace rest {
2710

2811
RestCatalog::RestCatalog(const std::string& base_url) : base_url_(std::move(base_url)) {}
2912

30-
void RestCatalog::testCprIntegration() {
31-
std::cout << "Testing CPR integration with base URL: " << base_url_ << std::endl;
32-
13+
cpr::Response RestCatalog::testCprIntegration() {
3314
// Simple GET request demo
3415
cpr::Response r =
3516
cpr::Get(cpr::Url{"https://httpbin.org/get"}, cpr::Parameters{{"hello", "world"}});
3617

37-
std::cout << "Status code: " << r.status_code << std::endl;
38-
std::cout << "Content-Type: " << r.header["content-type"] << std::endl;
39-
std::cout << "Response text (first 200 chars): "
40-
<< r.text.substr(0, std::min<size_t>(200, r.text.size())) << "..."
41-
<< std::endl;
42-
43-
// Simulated REST catalog API request
44-
std::string catalog_url = base_url_ + "/v1/namespaces";
45-
std::cout << "\nSimulated catalog request to: " << catalog_url << std::endl;
46-
47-
// In real implementation, this would be:
48-
// cpr::Response catalog_r = cpr::Get(cpr::Url{catalog_url},
49-
// cpr::Header{{"Content-Type", "application/json"}});
18+
return r;
5019
}
5120

5221
} // namespace rest

src/iceberg/catalog/rest/rest_catalog.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@
2020

2121
#include <string>
2222

23+
#include "cpr/response.h"
24+
2325
namespace iceberg {
2426
namespace catalog {
2527
namespace rest {
2628

2729
class RestCatalog {
2830
public:
29-
RestCatalog(const std::string& base_url);
31+
explicit RestCatalog(const std::string& base_url);
3032
~RestCatalog() = default;
3133

32-
void testCprIntegration();
34+
cpr::Response testCprIntegration();
3335

3436
private:
3537
std::string base_url_;

test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,8 @@ if(ICEBERG_BUILD_BUNDLE)
125125
parquet_schema_test.cc
126126
parquet_test.cc)
127127
endif()
128+
129+
if(ICEBERG_BUILD_REST_CATALOG)
130+
add_iceberg_test(rest_catalog_test SOURCES rest_catalog_test.cc)
131+
target_link_libraries(rest_catalog_test PRIVATE iceberg_rest_catalog_static)
132+
endif()

test/rest_catalog_test.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// In your test file, e.g., rest_catalog_test.cc
2+
3+
#include "iceberg/catalog/rest/rest_catalog.h"
4+
5+
#include <gmock/gmock.h>
6+
#include <gtest/gtest.h>
7+
8+
#include "cpr/error.h"
9+
#include "cpr/response.h"
10+
11+
namespace iceberg {
12+
namespace catalog {
13+
namespace rest {
14+
15+
class RestCatalogTest : public ::testing::Test {};
16+
17+
TEST_F(RestCatalogTest, CanCreateRestCatalog) {
18+
RestCatalog catalog("http://localhost:8181");
19+
SUCCEED();
20+
}
21+
22+
TEST_F(RestCatalogTest, MultipleCatalogInstances) {
23+
RestCatalog catalog1("http://localhost:8181");
24+
RestCatalog catalog2("http://localhost:8182");
25+
SUCCEED();
26+
}
27+
28+
TEST_F(RestCatalogTest, TestCprIntegration) {
29+
RestCatalog catalog("http://localhost:8181");
30+
31+
cpr::Response response = catalog.testCprIntegration();
32+
33+
ASSERT_EQ(response.error.code, cpr::ErrorCode::OK)
34+
<< "CPR transport error: " << response.error.message;
35+
36+
EXPECT_EQ(response.status_code, 200);
37+
EXPECT_THAT(response.text, ::testing::HasSubstr("\"hello\": \"world\""));
38+
}
39+
40+
} // namespace rest
41+
} // namespace catalog
42+
} // namespace iceberg

0 commit comments

Comments
 (0)