Skip to content

Commit b1901e7

Browse files
authored
test: add rest catalog integration test (apache#361)
Add integration testing infrastructure for the REST Catalog: - Docker Compose setup (`docker-compose.yml`) for running a real REST catalog server - Test utilities for process management (`cmd_util.cc/h`) - run cli commands - Docker Compose control utilities (`docker_compose_util.cc/h`) managing containerized services - Modified GitHub CI to support integration tests. - These test cases (cmd / docker compose related) only work on Linux, so added conditional compilation flags for Linux-specific test utilities.
1 parent c472f3c commit b1901e7

File tree

13 files changed

+471
-161
lines changed

13 files changed

+471
-161
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
env:
5555
CC: gcc-14
5656
CXX: g++-14
57-
run: ci/scripts/build_iceberg.sh $(pwd)
57+
run: ci/scripts/build_iceberg.sh $(pwd) ON
5858
- name: Build Example
5959
shell: bash
6060
env:
@@ -110,6 +110,7 @@ jobs:
110110
runs-on: ubuntu-24.04
111111
CC: gcc-14
112112
CXX: g++-14
113+
meson-setup-args: -Drest_integration_test=enabled
113114
- title: AMD64 Windows 2025
114115
runs-on: windows-2025
115116
meson-setup-args: --vsenv

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
4242
option(ICEBERG_BUILD_TESTS "Build tests" ON)
4343
option(ICEBERG_BUILD_BUNDLE "Build the battery included library" ON)
4444
option(ICEBERG_BUILD_REST "Build rest catalog client" ON)
45+
option(ICEBERG_BUILD_REST_INTEGRATION_TESTS "Build rest catalog integration tests" OFF)
4546
option(ICEBERG_ENABLE_ASAN "Enable Address Sanitizer" OFF)
4647
option(ICEBERG_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
4748

@@ -60,6 +61,11 @@ else()
6061
set(MSVC_TOOLCHAIN FALSE)
6162
endif()
6263

64+
if(ICEBERG_BUILD_REST_INTEGRATION_TESTS AND WIN32)
65+
set(ICEBERG_BUILD_REST_INTEGRATION_TESTS OFF)
66+
message(WARNING "Cannot build rest integration test on Windows, turning it off.")
67+
endif()
68+
6369
include(CMakeParseArguments)
6470
include(IcebergBuildUtils)
6571
include(IcebergSanitizer)

ci/scripts/build_iceberg.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set -eux
2121

2222
source_dir=${1}
2323
build_dir=${1}/build
24+
build_rest_integration_test=${2:-OFF}
2425

2526
mkdir ${build_dir}
2627
pushd ${build_dir}
@@ -34,6 +35,7 @@ CMAKE_ARGS=(
3435
"-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-${ICEBERG_HOME}}"
3536
"-DICEBERG_BUILD_STATIC=ON"
3637
"-DICEBERG_BUILD_SHARED=ON"
38+
"-DICEBERG_BUILD_REST_INTEGRATION_TESTS=${build_rest_integration_test}"
3739
)
3840

3941
if is_windows; then

meson.options

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ option(
3636
description: 'Build rest catalog client',
3737
value: 'enabled',
3838
)
39+
40+
option(
41+
'rest_integration_test',
42+
type: 'feature',
43+
description: 'Build integration test for rest catalog',
44+
value: 'disabled',
45+
)
46+
3947
option('tests', type: 'feature', description: 'Build tests', value: 'enabled')

src/iceberg/test/CMakeLists.txt

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,14 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
fetchcontent_declare(cpp-httplib
19-
GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
20-
GIT_TAG 89c932f313c6437c38f2982869beacc89c2f2246 #release-0.26.0
21-
)
22-
2318
fetchcontent_declare(googletest
2419
GIT_REPOSITORY https://github.com/google/googletest.git
2520
GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59 # release-1.15.2
2621
FIND_PACKAGE_ARGS
2722
NAMES
2823
GTest)
2924

30-
if(ICEBERG_BUILD_REST)
31-
fetchcontent_makeavailable(cpp-httplib googletest)
32-
else()
33-
fetchcontent_makeavailable(googletest)
34-
endif()
25+
fetchcontent_makeavailable(googletest)
3526

3627
set(ICEBERG_TEST_RESOURCES "${CMAKE_SOURCE_DIR}/src/iceberg/test/resources")
3728

@@ -53,11 +44,9 @@ function(add_iceberg_test test_name)
5344
target_sources(${test_name} PRIVATE ${ARG_SOURCES})
5445

5546
if(ARG_USE_BUNDLE)
56-
target_link_libraries(${test_name} PRIVATE iceberg_bundle_static GTest::gtest_main
57-
GTest::gmock)
47+
target_link_libraries(${test_name} PRIVATE iceberg_bundle_static GTest::gmock_main)
5848
else()
59-
target_link_libraries(${test_name} PRIVATE iceberg_static GTest::gtest_main
60-
GTest::gmock)
49+
target_link_libraries(${test_name} PRIVATE iceberg_static GTest::gmock_main)
6150
endif()
6251

6352
add_test(NAME ${test_name} COMMAND ${test_name})
@@ -173,16 +162,18 @@ if(ICEBERG_BUILD_REST)
173162
add_executable(${test_name})
174163
target_include_directories(${test_name} PRIVATE "${CMAKE_BINARY_DIR}/iceberg/test/")
175164
target_sources(${test_name} PRIVATE ${ARG_SOURCES})
176-
target_link_libraries(${test_name} PRIVATE GTest::gtest_main GTest::gmock
177-
iceberg_rest_static)
165+
target_link_libraries(${test_name} PRIVATE GTest::gmock_main iceberg_rest_static)
178166
add_test(NAME ${test_name} COMMAND ${test_name})
179167
endfunction()
180168

181-
add_rest_iceberg_test(rest_catalog_test
182-
SOURCES
183-
rest_catalog_test.cc
184-
rest_json_internal_test.cc
169+
add_rest_iceberg_test(rest_catalog_test SOURCES rest_json_internal_test.cc
185170
rest_util_test.cc)
186171

187-
target_include_directories(rest_catalog_test PRIVATE ${cpp-httplib_SOURCE_DIR})
172+
if(ICEBERG_BUILD_REST_INTEGRATION_TESTS)
173+
add_rest_iceberg_test(rest_catalog_integration_test
174+
SOURCES
175+
rest_catalog_test.cc
176+
util/cmd_util.cc
177+
util/docker_compose_util.cc)
178+
endif()
188179
endif()

src/iceberg/test/meson.build

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,28 @@ iceberg_tests = {
9191
}
9292

9393
if get_option('rest').enabled()
94-
cpp_httplib_dep = dependency('cpp-httplib')
9594
iceberg_tests += {
9695
'rest_catalog_test': {
97-
'sources': files(
98-
'rest_catalog_test.cc',
99-
'rest_json_internal_test.cc',
100-
'rest_util_test.cc',
101-
),
102-
'dependencies': [iceberg_rest_dep, cpp_httplib_dep],
96+
'sources': files('rest_json_internal_test.cc', 'rest_util_test.cc'),
97+
'dependencies': [iceberg_rest_dep],
10398
},
10499
}
100+
if get_option('rest_integration_test').enabled()
101+
if host_machine.system() == 'windows'
102+
warning('Cannot build rest integration test on Windows, skipping.')
103+
else
104+
iceberg_tests += {
105+
'rest_integration_test': {
106+
'sources': files(
107+
'rest_catalog_test.cc',
108+
'util/cmd_util.cc',
109+
'util/docker_compose_util.cc',
110+
),
111+
'dependencies': [iceberg_rest_dep],
112+
},
113+
}
114+
endif
115+
endif
105116
endif
106117

107118
foreach test_name, values : iceberg_tests

subprojects/cpp-httplib.wrap renamed to src/iceberg/test/resources/iceberg-rest-fixture/docker-compose.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
[wrap-file]
19-
directory = cpp-httplib-0.26.0
20-
source_url = https://github.com/yhirose/cpp-httplib/archive/refs/tags/v0.26.0.tar.gz
21-
source_filename = cpp-httplib-0.26.0.tar.gz
22-
source_hash = a66f908f50ccb119769adce44fe1eac75f81b6ffab7c4ac0211bb663ffeb2688
23-
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/cpp-httplib_0.26.0-1/cpp-httplib-0.26.0.tar.gz
24-
wrapdb_version = 0.26.0-1
25-
26-
[provide]
27-
dependency_names = cpp-httplib
18+
services:
19+
rest:
20+
image: apache/iceberg-rest-fixture:latest
21+
environment:
22+
- CATALOG_CATALOG__IMPL=org.apache.iceberg.jdbc.JdbcCatalog
23+
- CATALOG_URI=jdbc:sqlite:file:/tmp/iceberg_rest_mode=memory
24+
- CATALOG_WAREHOUSE=file:///tmp/iceberg_warehouse
25+
ports:
26+
- "8181:8181"

0 commit comments

Comments
 (0)