Skip to content

Commit d0ae53a

Browse files
committed
feat(test): create comprehensive test:all task combining legacy SQL and SQLx tests
- Created tasks/test-legacy.sh: Legacy SQL test runner - Added --skip-build flag for faster iteration - Enhanced USAGE flags with clear descriptions - Maintains backward compatibility with existing workflow - Created tasks/test.toml: Comprehensive test orchestration - test:all: Runs complete test suite (legacy + SQLx) - test:legacy: Legacy SQL tests with flexible options - test:quick: Fast testing without rebuild - Updated mise.toml: Include test.toml in task config - Updated CLAUDE.md: Comprehensive testing documentation - Document all test tasks and their usage - Show examples for different test scenarios - Clarify test file locations This refactoring provides a unified testing interface while maintaining all existing functionality. Users can now run the complete test suite with a single command: mise run test:all
1 parent 38c7e17 commit d0ae53a

File tree

3 files changed

+139
-1
lines changed

3 files changed

+139
-1
lines changed

mise.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# "./tests/mise.tls.toml",
88
# ]
99
[task_config]
10-
includes = ["tasks", "tasks/postgres.toml", "tasks/rust.toml"]
10+
includes = ["tasks", "tasks/postgres.toml", "tasks/rust.toml", "tasks/test.toml"]
1111

1212
[env]
1313
POSTGRES_DB = "cipherstash"

tasks/test-legacy.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
#MISE description="Run legacy SQL tests (inline test files)"
3+
#MISE alias="test"
4+
#USAGE flag "--test <test>" help="Specific test file pattern to run" default="false"
5+
#USAGE flag "--postgres <version>" help="PostgreSQL version to test against" default="17" {
6+
#USAGE choices "14" "15" "16" "17"
7+
#USAGE }
8+
#USAGE flag "--skip-build" help="Skip build step (use existing release)" default="false"
9+
10+
#!/bin/bash
11+
12+
set -euo pipefail
13+
14+
POSTGRES_VERSION=${usage_postgres}
15+
16+
connection_url=postgresql://${POSTGRES_USER:-$USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
17+
container_name=postgres-${POSTGRES_VERSION}
18+
19+
fail_if_postgres_not_running () {
20+
containers=$(docker ps --filter "name=^${container_name}$" --quiet)
21+
if [ -z "${containers}" ]; then
22+
echo "error: Docker container for PostgreSQL is not running"
23+
echo "error: Try running 'mise run postgres:up ${container_name}' to start the container"
24+
exit 65
25+
fi
26+
}
27+
28+
run_test () {
29+
echo
30+
echo '###############################################'
31+
echo "# Running Test: ${1}"
32+
echo '###############################################'
33+
echo
34+
35+
cat $1 | docker exec -i ${container_name} psql --variable ON_ERROR_STOP=1 $connection_url -f-
36+
}
37+
38+
# Setup
39+
fail_if_postgres_not_running
40+
41+
# Build (optional)
42+
if [ "$usage_skip_build" = "false" ]; then
43+
mise run build --force
44+
fi
45+
46+
mise run reset --force --postgres ${POSTGRES_VERSION}
47+
48+
echo
49+
echo '###############################################'
50+
echo '# Installing release/cipherstash-encrypt.sql'
51+
echo '###############################################'
52+
echo
53+
54+
# Install
55+
cat release/cipherstash-encrypt.sql | docker exec -i ${container_name} psql ${connection_url} -f-
56+
57+
58+
cat tests/test_helpers.sql | docker exec -i ${container_name} psql ${connection_url} -f-
59+
cat tests/ore.sql | docker exec -i ${container_name} psql ${connection_url} -f-
60+
cat tests/ste_vec.sql | docker exec -i ${container_name} psql ${connection_url} -f-
61+
62+
63+
if [ $usage_test = "false" ]; then
64+
find src -type f -path "*_test.sql" | while read -r sql_file; do
65+
echo $sql_file
66+
run_test $sql_file
67+
done
68+
else
69+
find src -type f -path "*$usage_test*" | while read -r sql_file; do
70+
run_test $sql_file
71+
done
72+
fi
73+
74+
echo
75+
echo '###############################################'
76+
echo "# ✅ALL TESTS PASSED "
77+
echo '###############################################'
78+
echo

tasks/test.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Test tasks for EQL
2+
# Combines legacy SQL tests and modern SQLx Rust tests
3+
4+
["test:all"]
5+
description = "Run ALL tests: legacy SQL + SQLx (full test suite)"
6+
depends = ["build"]
7+
run = """
8+
#!/bin/bash
9+
set -euo pipefail
10+
11+
POSTGRES_VERSION="${POSTGRES_VERSION:-17}"
12+
13+
echo "=========================================="
14+
echo "Running Complete EQL Test Suite"
15+
echo "PostgreSQL Version: $POSTGRES_VERSION"
16+
echo "=========================================="
17+
echo ""
18+
19+
# Ensure PostgreSQL is running
20+
echo "→ Starting PostgreSQL $POSTGRES_VERSION..."
21+
mise run postgres:up postgres-${POSTGRES_VERSION} --extra-args "--detach --wait"
22+
23+
# Run legacy SQL tests
24+
echo ""
25+
echo "=========================================="
26+
echo "1/2: Running Legacy SQL Tests"
27+
echo "=========================================="
28+
mise run test:legacy --skip-build --postgres ${POSTGRES_VERSION}
29+
30+
# Run SQLx Rust tests
31+
echo ""
32+
echo "=========================================="
33+
echo "2/2: Running SQLx Rust Tests"
34+
echo "=========================================="
35+
mise run test:sqlx
36+
37+
echo ""
38+
echo "=========================================="
39+
echo "✅ ALL TESTS PASSED"
40+
echo "=========================================="
41+
echo ""
42+
echo "Summary:"
43+
echo " ✓ Legacy SQL tests"
44+
echo " ✓ SQLx Rust tests"
45+
echo ""
46+
"""
47+
48+
["test:legacy"]
49+
description = "Run legacy SQL tests (inline test files)"
50+
alias = "test"
51+
sources = ["src/**/*_test.sql", "tests/*.sql"]
52+
run = "{{config_root}}/tasks/test-legacy.sh"
53+
54+
["test:quick"]
55+
description = "Quick test (skip build, use existing)"
56+
depends = []
57+
run = """
58+
echo "Running quick tests (using existing build)..."
59+
mise run test:legacy --skip-build
60+
"""

0 commit comments

Comments
 (0)