Skip to content

Commit 5c03f45

Browse files
committed
feat: add driver abstraction to generate.sh
Replaces hardcoded docker exec/cp calls with pluggable driver functions, making fixture generation usable without Docker. Driver API (exec_sysdba, exec_user, oracle_spool_path, fetch_spool, fetch_archive, olr_path, run_olr) selected via ORACLE_DRIVER env var. Included drivers: - docker (default): docker exec + compose exec, existing behaviour - local: local sqlplus + OLR binary, no Docker needed Usage: ORACLE_DRIVER=local OLR_BINARY=/path/to/OpenLogReplicator ./generate.sh basic-crud
1 parent 006fa41 commit 5c03f45

3 files changed

Lines changed: 162 additions & 85 deletions

File tree

tests/scripts/drivers/docker.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
# Driver: docker
3+
# Oracle via docker exec, OLR via docker compose exec.
4+
# This is the default driver. Used when ORACLE_DRIVER=docker (or unset).
5+
#
6+
# Additional env vars (optional):
7+
# ORACLE_CONTAINER — Docker container running Oracle (default: oracle)
8+
# DOCKER_EXEC_USER — User for docker exec (set to "oracle" for official images)
9+
10+
: "${ORACLE_CONTAINER:=oracle}"
11+
12+
_DEXEC="docker exec"
13+
if [[ -n "${DOCKER_EXEC_USER:-}" ]]; then
14+
_DEXEC="docker exec -u $DOCKER_EXEC_USER"
15+
fi
16+
17+
_CONTAINER_TESTS="/opt/OpenLogReplicator-local/tests"
18+
_OLR_BINARY="/opt/OpenLogReplicator/OpenLogReplicator"
19+
20+
# Validate environment directory and set COMPOSE
21+
[[ -d "$ENV_DIR" ]] || { echo "ERROR: Environment directory not found: $ENV_DIR" >&2; exit 1; }
22+
COMPOSE="docker compose -f $ENV_DIR/docker-compose.yaml"
23+
24+
# Run SQL as sysdba; returns stdout
25+
exec_sysdba() {
26+
local sql_file="$1"
27+
local remote="/tmp/$(basename "$sql_file")"
28+
docker cp "$sql_file" "${ORACLE_CONTAINER}:${remote}"
29+
$_DEXEC "$ORACLE_CONTAINER" sqlplus -S / as sysdba @"$remote"
30+
}
31+
32+
# Run SQL as test user; returns stdout
33+
exec_user() {
34+
local sql_file="$1"
35+
local remote="/tmp/$(basename "$sql_file")"
36+
docker cp "$sql_file" "${ORACLE_CONTAINER}:${remote}"
37+
$_DEXEC "$ORACLE_CONTAINER" sqlplus -S "$DB_CONN" @"$remote"
38+
}
39+
40+
# Path for SPOOL directive (inside Oracle container filesystem)
41+
oracle_spool_path() {
42+
echo "/tmp/olr_spool.lst"
43+
}
44+
45+
# Copy spool output back to a local file
46+
fetch_spool() {
47+
docker cp "${ORACLE_CONTAINER}:/tmp/olr_spool.lst" "$1"
48+
}
49+
50+
# Copy an archive log from Oracle container to a local path
51+
fetch_archive() {
52+
docker cp "${ORACLE_CONTAINER}:$1" "$2"
53+
}
54+
55+
# Convert a host-side absolute path to the OLR-visible path inside its container
56+
# (tests/ is bind-mounted at _CONTAINER_TESTS in the olr compose service)
57+
olr_path() {
58+
echo "${_CONTAINER_TESTS}/${1#$TESTS_DIR/}"
59+
}
60+
61+
# Run OLR with the given config file (host path); caller redirects stdout/stderr
62+
run_olr() {
63+
local host_config="$1"
64+
$COMPOSE exec -T olr \
65+
"$_OLR_BINARY" -r -f "$(olr_path "$host_config")"
66+
}

tests/scripts/drivers/local.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
# Driver: local
3+
# Oracle via local sqlplus, OLR binary on local filesystem.
4+
# Use this when Oracle and OLR are installed locally (no Docker needed).
5+
#
6+
# Required env vars:
7+
# OLR_BINARY — path to OpenLogReplicator binary
8+
#
9+
# Optional env vars:
10+
# ORACLE_SID — set if needed for OS authentication (/ as sysdba)
11+
# DB_CONN — sqlplus connect string for test user (set in generate.sh)
12+
13+
OLR_BINARY="${OLR_BINARY:?OLR_BINARY must be set for the local driver (path to OpenLogReplicator binary)}"
14+
15+
# No environment directory needed for local Oracle
16+
# No COMPOSE setup needed
17+
18+
# Run SQL as sysdba; returns stdout
19+
exec_sysdba() {
20+
sqlplus -S / as sysdba @"$1"
21+
}
22+
23+
# Run SQL as test user; returns stdout
24+
exec_user() {
25+
sqlplus -S "$DB_CONN" @"$1"
26+
}
27+
28+
# Path for SPOOL directive (local filesystem, directly in work dir)
29+
oracle_spool_path() {
30+
echo "$WORK_DIR/olr_spool.lst"
31+
}
32+
33+
# Fetch spool output — already local, no-op if dest matches spool path
34+
fetch_spool() {
35+
local dest="$1"
36+
[[ "$dest" != "$(oracle_spool_path)" ]] && cp "$(oracle_spool_path)" "$dest"
37+
}
38+
39+
# Copy an archive log from Oracle filesystem to a local path
40+
# (for local Oracle, archive path is already on local filesystem)
41+
fetch_archive() {
42+
cp "$1" "$2"
43+
}
44+
45+
# No path mapping needed — OLR runs on the same filesystem
46+
olr_path() {
47+
echo "$1"
48+
}
49+
50+
# Run OLR with the given config file; caller redirects stdout/stderr
51+
run_olr() {
52+
"$OLR_BINARY" -r -f "$1"
53+
}

0 commit comments

Comments
 (0)