Skip to content

Commit d389280

Browse files
committed
refactor: replace C++ gtest with shell script test runner
- Remove tests/test_pipeline.cpp and tests/CMakeLists.txt (gtest infrastructure) - Remove WITHTESTS build arg from Dockerfile.dev, Makefile, and CI workflows - Add tests/run-fixtures.sh: discovers and runs fixtures without compilation - Update redo-log-tests.yaml to use shell script instead of ctest - Fix example/setup.sql to use PL/SQL DROP for pre-23c compatibility
1 parent f880a19 commit d389280

10 files changed

Lines changed: 268 additions & 387 deletions

File tree

.github/workflows/redo-log-tests.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ jobs:
4646
WITHKAFKA=1
4747
WITHPROTOBUF=1
4848
WITHPROMETHEUS=1
49-
WITHTESTS=1
5049
5150
- name: Download fixtures from sql-tests-free23
5251
uses: dawidd6/action-download-artifact@v6
@@ -65,4 +64,8 @@ jobs:
6564
if_no_artifact_found: warn
6665

6766
- name: Run redo log tests
68-
run: make test-redo
67+
run: |
68+
docker run --rm \
69+
-v ${{ github.workspace }}/tests:/opt/OpenLogReplicator-local/tests \
70+
--entrypoint bash olr-dev:latest \
71+
-c "TESTS_DIR=/opt/OpenLogReplicator-local/tests /opt/OpenLogReplicator-local/tests/run-fixtures.sh"

.github/workflows/sql-tests-free23.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ jobs:
4444
WITHKAFKA=1
4545
WITHPROTOBUF=1
4646
WITHPROMETHEUS=1
47-
WITHTESTS=1
4847
4948
- name: Start containers
5049
run: make -C tests/sql/environments/${{ env.ORACLE_TARGET }} up

.github/workflows/sql-tests-xe21.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ jobs:
4444
WITHKAFKA=1
4545
WITHPROTOBUF=1
4646
WITHPROMETHEUS=1
47-
WITHTESTS=1
4847
4948
- name: Start containers
5049
run: make -C tests/sql/environments/${{ env.ORACLE_TARGET }} up

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ if (WITH_PROTOBUF)
127127
endif ()
128128

129129
add_subdirectory(src)
130-
if (WITH_TESTS)
131-
enable_testing()
132-
add_subdirectory(tests)
133-
endif ()
134130

135131
target_link_libraries(OpenLogReplicator Threads::Threads)
136132

Dockerfile.dev

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ARG WITHKAFKA
1919
ARG WITHPROMETHEUS
2020
ARG WITHORACLE
2121
ARG WITHPROTOBUF
22-
ARG WITHTESTS
2322

2423
ENV LC_ALL=C
2524
ENV LANG=en_US.UTF-8
@@ -37,7 +36,6 @@ ENV BUILDARGS="${BUILDARGS}${WITHKAFKA:+ -DWITH_RDKAFKA=/opt/librdkafka}"
3736
ENV BUILDARGS="${BUILDARGS}${WITHPROMETHEUS:+ -DWITH_PROMETHEUS=/opt/prometheus}"
3837
ENV BUILDARGS="${BUILDARGS}${WITHORACLE:+ -DWITH_OCI=/opt/instantclient_${ORACLE_MAJOR}_${ORACLE_MINOR}}"
3938
ENV BUILDARGS="${BUILDARGS}${WITHPROTOBUF:+ -DWITH_PROTOBUF=/opt/protobuf}"
40-
ENV BUILDARGS="${BUILDARGS}${WITHTESTS:+ -DWITH_TESTS=ON}"
4139
ENV COMPILEKAFKA="${WITHKAFKA:+1}"
4240
ENV COMPILEPROMETHEUS="${WITHPROMETHEUS:+1}"
4341
ENV COMPILEORACLE="${WITHORACLE:+1}"
@@ -143,9 +141,6 @@ RUN --mount=type=cache,target=/root/.ccache,id=olr-ccache \
143141
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
144142
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache && \
145143
cmake --build ./ --target OpenLogReplicator -j && \
146-
if [ "${WITHTESTS}" != "" ]; then \
147-
cmake --build ./ --target olr_tests -j ; \
148-
fi && \
149144
mkdir -p /opt/OpenLogReplicator/log /opt/OpenLogReplicator/tmp /opt/OpenLogReplicator/scripts && \
150145
cp ./OpenLogReplicator /opt/OpenLogReplicator && \
151146
cp -p /opt/OpenLogReplicator-local/scripts/gencfg.sql /opt/OpenLogReplicator/scripts/gencfg.sql

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
OLR_IMAGE ?= olr-dev:latest
22
CACHE_IMAGE ?= ghcr.io/bersler/openlogreplicator:ci
33
BUILD_TYPE ?= Debug
4-
OLR_BUILD_DIR ?= /opt/OpenLogReplicator-local/cmake-build-$(BUILD_TYPE)-x86_64
54

65
.PHONY: build test-redo clean
76

@@ -15,7 +14,6 @@ build:
1514
--build-arg WITHKAFKA=1 \
1615
--build-arg WITHPROTOBUF=1 \
1716
--build-arg WITHPROMETHEUS=1 \
18-
--build-arg WITHTESTS=1 \
1917
--cache-from type=registry,ref=$(CACHE_IMAGE) \
2018
-t $(OLR_IMAGE) \
2119
--load \
@@ -25,7 +23,7 @@ test-redo:
2523
docker run --rm \
2624
-v $(CURDIR)/tests:/opt/OpenLogReplicator-local/tests \
2725
--entrypoint bash $(OLR_IMAGE) \
28-
-c "ctest --test-dir $(OLR_BUILD_DIR) --output-on-failure"
26+
-c "TESTS_DIR=/opt/OpenLogReplicator-local/tests /opt/OpenLogReplicator-local/tests/run-fixtures.sh"
2927

3028
clean:
3129
rm -rf tests/sql/generated tests/.work

tests/CMakeLists.txt

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/run-fixtures.sh

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
#!/usr/bin/env bash
2+
# run-fixtures.sh — Run OLR in batch mode against redo log fixtures
3+
# and compare output against golden files.
4+
#
5+
# Usage: ./run-fixtures.sh [fixture-name ...]
6+
# No arguments: auto-discover all fixtures from fixtures/ and sql/generated/
7+
# With arguments: run only the named fixtures
8+
#
9+
# Environment:
10+
# OLR_BINARY — path to OLR binary (default: auto-detect from cmake build dir)
11+
# TESTS_DIR — path to tests/ directory (default: directory containing this script)
12+
13+
set -euo pipefail
14+
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
TESTS_DIR="${TESTS_DIR:-$SCRIPT_DIR}"
17+
18+
# Auto-detect OLR binary
19+
if [[ -z "${OLR_BINARY:-}" ]]; then
20+
for candidate in \
21+
/opt/OpenLogReplicator/OpenLogReplicator \
22+
/opt/OpenLogReplicator-local/cmake-build-Debug-x86_64/OpenLogReplicator \
23+
"$TESTS_DIR/../cmake-build-Debug-x86_64/OpenLogReplicator" \
24+
"$TESTS_DIR/../build/OpenLogReplicator"; do
25+
if [[ -x "$candidate" ]]; then
26+
OLR_BINARY="$candidate"
27+
break
28+
fi
29+
done
30+
fi
31+
if [[ -z "${OLR_BINARY:-}" ]]; then
32+
echo "ERROR: OLR binary not found. Set OLR_BINARY env var." >&2
33+
exit 1
34+
fi
35+
36+
# --- Discover fixtures ---
37+
discover_fixtures() {
38+
local base_dir="$1" # e.g., fixtures or sql/generated
39+
local dir="$TESTS_DIR/$base_dir/expected"
40+
[[ -d "$dir" ]] || return 0
41+
for scenario_dir in "$dir"/*/; do
42+
[[ -f "${scenario_dir}output.json" ]] || continue
43+
echo "$base_dir/$(basename "$scenario_dir")"
44+
done
45+
}
46+
47+
if [[ $# -gt 0 ]]; then
48+
FIXTURES=("$@")
49+
else
50+
FIXTURES=()
51+
while IFS= read -r f; do
52+
FIXTURES+=("$f")
53+
done < <({ discover_fixtures "fixtures"; discover_fixtures "sql/generated"; } | sort)
54+
fi
55+
56+
if [[ ${#FIXTURES[@]} -eq 0 ]]; then
57+
echo "No fixtures found."
58+
exit 0
59+
fi
60+
61+
# --- Detect archive format from redo filenames ---
62+
detect_archive_format() {
63+
local redo_dir="$1"
64+
local sample
65+
sample=$(ls "$redo_dir"/* 2>/dev/null | head -1)
66+
[[ -n "$sample" ]] || { echo "%t_%s_%r.dbf"; return; }
67+
local fname
68+
fname=$(basename "$sample")
69+
local stem="${fname%.*}"
70+
local ext="${fname##*.}"
71+
# Expected: [prefix]<thread>_<seq>_<resetlogs>.<ext>
72+
local resetlogs="${stem##*_}"
73+
local rest="${stem%_*}"
74+
local seq="${rest##*_}"
75+
local prefix_thread="${rest%_*}"
76+
# prefix_thread is e.g. "arch1" — split into prefix + thread
77+
local thread="${prefix_thread##*[!0-9]}"
78+
local prefix="${prefix_thread%$thread}"
79+
echo "${prefix}%t_%s_%r.${ext}"
80+
}
81+
82+
# --- Find schema checkpoint and extract start SCN ---
83+
find_schema() {
84+
local schema_dir="$1"
85+
[[ -d "$schema_dir" ]] || return 1
86+
local best_file="" best_scn=999999999999
87+
for f in "$schema_dir"/TEST-chkpt-*.json; do
88+
[[ -f "$f" ]] || continue
89+
local fname
90+
fname=$(basename "$f")
91+
# Extract SCN from TEST-chkpt-<scn>.json
92+
local scn="${fname#TEST-chkpt-}"
93+
scn="${scn%.json}"
94+
if [[ "$scn" -lt "$best_scn" ]] 2>/dev/null; then
95+
best_scn="$scn"
96+
best_file="$f"
97+
fi
98+
done
99+
[[ -n "$best_file" ]] || return 1
100+
echo "$best_scn $best_file"
101+
}
102+
103+
# --- Run one fixture ---
104+
run_fixture() {
105+
local fixture="$1"
106+
local scenario="${fixture##*/}"
107+
local dir_prefix="${fixture%/*}"
108+
109+
case "$dir_prefix" in
110+
fixtures|sql/generated) ;;
111+
*) echo "FAIL $fixture (unknown prefix: $dir_prefix)"; return 1 ;;
112+
esac
113+
114+
local redo_dir="$TESTS_DIR/$dir_prefix/redo/$scenario"
115+
local schema_dir="$TESTS_DIR/$dir_prefix/schema/$scenario"
116+
local expected="$TESTS_DIR/$dir_prefix/expected/$scenario/output.json"
117+
118+
if [[ ! -d "$redo_dir" ]]; then
119+
echo "FAIL $fixture (redo logs missing: $redo_dir)"
120+
return 1
121+
fi
122+
123+
# Temp dir for this test
124+
local tmp_dir
125+
tmp_dir=$(mktemp -d)
126+
trap "rm -rf '$tmp_dir'" RETURN
127+
128+
# Collect redo log files
129+
local redo_json="["
130+
local first=1
131+
for f in "$redo_dir"/*; do
132+
[[ -f "$f" ]] || continue
133+
[[ $first -eq 1 ]] && first=0 || redo_json+=", "
134+
redo_json+="\"$f\""
135+
done
136+
redo_json+="]"
137+
138+
local archive_format
139+
archive_format=$(detect_archive_format "$redo_dir")
140+
141+
# Schema detection
142+
local reader_extra="" flags_line="" filter_section=""
143+
local schema_info
144+
if schema_info=$(find_schema "$schema_dir"); then
145+
local start_scn="${schema_info%% *}"
146+
local schema_file="${schema_info#* }"
147+
cp "$schema_file" "$tmp_dir/"
148+
reader_extra=$(printf ',\n "log-archive-format": "%s",\n "start-scn": %s' "$archive_format" "$start_scn")
149+
filter_section=',
150+
"filter": {
151+
"table": [
152+
{"owner": "OLR_TEST", "table": ".*"}
153+
]
154+
}'
155+
else
156+
reader_extra=$(printf ',\n "log-archive-format": ""')
157+
flags_line=',
158+
"flags": 2'
159+
fi
160+
161+
local output="$tmp_dir/output.json"
162+
163+
cat > "$tmp_dir/config.json" <<EOF
164+
{
165+
"version": "1.9.0",
166+
"log-level": 3,
167+
"memory": {
168+
"min-mb": 32,
169+
"max-mb": 256
170+
},
171+
"state": {
172+
"type": "disk",
173+
"path": "$tmp_dir"
174+
},
175+
"source": [
176+
{
177+
"alias": "S1",
178+
"name": "TEST",
179+
"reader": {
180+
"type": "batch",
181+
"redo-log": $redo_json$reader_extra
182+
},
183+
"format": {
184+
"type": "json",
185+
"scn": 1,
186+
"timestamp": 7,
187+
"timestamp-metadata": 7,
188+
"xid": 1
189+
}$flags_line$filter_section
190+
}
191+
],
192+
"target": [
193+
{
194+
"alias": "T1",
195+
"source": "S1",
196+
"writer": {
197+
"type": "file",
198+
"output": "$output",
199+
"new-line": 1,
200+
"append": 1
201+
}
202+
}
203+
]
204+
}
205+
EOF
206+
207+
# Run OLR
208+
local olr_log="$tmp_dir/olr.log"
209+
if ! "$OLR_BINARY" -r -f "$tmp_dir/config.json" > "$olr_log" 2>&1; then
210+
echo "FAIL $fixture (OLR exited with error)"
211+
cat "$olr_log" >&2
212+
return 1
213+
fi
214+
215+
if [[ ! -f "$output" ]]; then
216+
echo "FAIL $fixture (no output file)"
217+
cat "$olr_log" >&2
218+
return 1
219+
fi
220+
221+
# Compare against golden file
222+
local diff_out
223+
if diff_out=$(diff --unified "$expected" "$output"); then
224+
echo "PASS $fixture"
225+
return 0
226+
else
227+
echo "FAIL $fixture (output differs)"
228+
echo "$diff_out" >&2
229+
return 1
230+
fi
231+
}
232+
233+
# --- Main ---
234+
passed=0
235+
failed=0
236+
failures=()
237+
238+
echo "Running ${#FIXTURES[@]} fixture(s)..."
239+
echo ""
240+
241+
for fixture in "${FIXTURES[@]}"; do
242+
if run_fixture "$fixture"; then
243+
((passed++)) || true
244+
else
245+
((failed++)) || true
246+
failures+=("$fixture")
247+
fi
248+
done
249+
250+
echo ""
251+
echo "Results: $passed passed, $failed failed, $((passed + failed)) total"
252+
253+
if [[ $failed -gt 0 ]]; then
254+
echo ""
255+
echo "Failed:"
256+
for f in "${failures[@]}"; do
257+
echo " $f"
258+
done
259+
exit 1
260+
fi

tests/sql/inputs/example/setup.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
DROP TABLE IF EXISTS TEST_CDC PURGE;
1+
BEGIN EXECUTE IMMEDIATE 'DROP TABLE TEST_CDC PURGE'; EXCEPTION WHEN OTHERS THEN NULL; END;
2+
/
23

34
CREATE TABLE TEST_CDC (
45
id NUMBER PRIMARY KEY,

0 commit comments

Comments
 (0)