Skip to content

Commit a7f03e0

Browse files
dev_server: add test
1 parent 92f878f commit a7f03e0

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/bash
2+
# Copyright (c) 2026 VillageSQL Contributors
3+
# Integration test for the VillageSQL dev server control script.
4+
#
5+
# Usage: integration_test.sh <package-dir>
6+
#
7+
# <package-dir> is the root of an extracted villagesql-dev-server-* tarball,
8+
# containing the villagesql script and the bin/, mysql-test/, etc. directories.
9+
#
10+
# The test spins up a real server in a temporary instance directory, exercises
11+
# each sub-command, then shuts it down and cleans up.
12+
13+
PACKAGE_DIR="${1:?Usage: $0 <package-dir>}"
14+
VSQL="$PACKAGE_DIR/villagesql"
15+
16+
if [[ ! -f "$VSQL" ]]; then
17+
echo "Error: villagesql script not found at $VSQL"
18+
exit 1
19+
fi
20+
21+
INSTANCE_DIR="$(mktemp -d)"
22+
PASS=0
23+
FAIL=0
24+
25+
cleanup() {
26+
"$VSQL" --dir "$INSTANCE_DIR" stop 2>/dev/null || true
27+
rm -rf "$INSTANCE_DIR"
28+
}
29+
trap cleanup EXIT
30+
31+
# ---------------------------------------------------------------------------
32+
# Test helpers
33+
# ---------------------------------------------------------------------------
34+
35+
run_test() {
36+
local desc="$1"
37+
local expected="$2" # "success" or "failure"
38+
shift 2
39+
40+
if "$@" >/dev/null 2>&1; then
41+
actual="success"
42+
else
43+
actual="failure"
44+
fi
45+
46+
if [[ "$actual" == "$expected" ]]; then
47+
echo "PASS: $desc"
48+
PASS=$((PASS + 1))
49+
else
50+
echo "FAIL: $desc (expected $expected, got $actual)"
51+
FAIL=$((FAIL + 1))
52+
fi
53+
}
54+
55+
run_test_output() {
56+
local desc="$1"
57+
local pattern="$2"
58+
shift 2
59+
60+
local output
61+
output=$("$@" 2>&1) || true
62+
if echo "$output" | grep -qF "$pattern"; then
63+
echo "PASS: $desc"
64+
PASS=$((PASS + 1))
65+
else
66+
echo "FAIL: $desc"
67+
echo " Expected output containing: $pattern"
68+
echo " Got: $output"
69+
FAIL=$((FAIL + 1))
70+
fi
71+
}
72+
73+
# ---------------------------------------------------------------------------
74+
# Tests
75+
# ---------------------------------------------------------------------------
76+
77+
echo "Testing VillageSQL dev server"
78+
echo " Package directory: $PACKAGE_DIR"
79+
echo " Instance directory: $INSTANCE_DIR"
80+
echo ""
81+
82+
# Help and error handling
83+
run_test_output "help shows usage" "Usage:" "$VSQL" help
84+
run_test_output "--help shows usage" "Usage:" "$VSQL" --help
85+
run_test "unknown command fails" failure "$VSQL" unknown_command_xyz
86+
87+
# Pre-init state
88+
run_test "status before init fails" failure "$VSQL" --dir "$INSTANCE_DIR" status
89+
run_test "start before init fails" failure "$VSQL" --dir "$INSTANCE_DIR" start
90+
run_test "stop before init fails" failure "$VSQL" --dir "$INSTANCE_DIR" stop
91+
92+
# Initialization
93+
run_test "init succeeds" success "$VSQL" --dir "$INSTANCE_DIR" init
94+
run_test "double init fails" failure "$VSQL" --dir "$INSTANCE_DIR" init
95+
96+
# Post-init, pre-start state
97+
run_test "status before start fails" failure "$VSQL" --dir "$INSTANCE_DIR" status
98+
99+
# Start
100+
run_test "start succeeds" success "$VSQL" --dir "$INSTANCE_DIR" start
101+
run_test "double start fails" failure "$VSQL" --dir "$INSTANCE_DIR" start
102+
103+
# Running state
104+
run_test "status while running succeeds" success "$VSQL" --dir "$INSTANCE_DIR" status
105+
run_test_output "connect can run SELECT 1" "1" "$VSQL" --dir "$INSTANCE_DIR" connect -e "SELECT 1"
106+
run_test "veb ls succeeds" success "$VSQL" --dir "$INSTANCE_DIR" veb ls
107+
108+
# veb add/rm
109+
TMPVEB="$(mktemp /tmp/test_XXXXXX.veb)"
110+
run_test "veb add succeeds" success "$VSQL" --dir "$INSTANCE_DIR" veb add "$TMPVEB"
111+
run_test_output "veb ls shows added extension" "$(basename "$TMPVEB" .veb)" \
112+
"$VSQL" --dir "$INSTANCE_DIR" veb ls
113+
run_test "veb rm succeeds" success "$VSQL" --dir "$INSTANCE_DIR" veb rm "$(basename "$TMPVEB" .veb)"
114+
run_test "veb rm missing fails" failure "$VSQL" --dir "$INSTANCE_DIR" veb rm nonexistent_ext
115+
rm -f "$TMPVEB"
116+
117+
# Stop
118+
run_test "stop succeeds" success "$VSQL" --dir "$INSTANCE_DIR" stop
119+
run_test "status after stop fails" failure "$VSQL" --dir "$INSTANCE_DIR" status
120+
run_test "double stop fails" failure "$VSQL" --dir "$INSTANCE_DIR" stop
121+
122+
# ---------------------------------------------------------------------------
123+
# Summary
124+
# ---------------------------------------------------------------------------
125+
126+
echo ""
127+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
128+
echo "Results: $PASS passed, $FAIL failed"
129+
[[ $FAIL -eq 0 ]] || exit 1

0 commit comments

Comments
 (0)