Skip to content

Conversation

tobyhede
Copy link
Contributor

Overview

This is an experimental branch exploring SQLx (Rust) as an alternative testing approach for EQL, with comprehensive analysis comparing different testing frameworks.

⚠️ Note: This branch contains an alternative approach to PR #135 (pgTAP testing). It's meant for evaluation and discussion, not immediate merging.

What's Included

1. SQLx/Rust Testing Infrastructure

  • rust-tests/ directory with Cargo project
  • Example test: add_column_test.rs demonstrating Rust+SQLx testing patterns
  • Test runner script: rust-tests/run-tests.sh
  • Async test support with connection pooling

2. Comprehensive Documentation

TESTING_FRAMEWORK_COMPARISON.md (597 lines)

Detailed analysis of testing approaches:

  • pgTAP: PostgreSQL-native testing (SQL-based)
  • SQLx/Rust: Type-safe testing with Rust
  • Component System: Previous attempt at Rust-based tooling
  • Side-by-side comparisons with examples
  • Pros/cons for each approach
  • Recommendations based on project needs

SQLX_TESTING_APPROACH.md (155 lines)

  • Problem statement: Why the Rust component system was too complex
  • Proposed solution: Use SQLx for tests, keep bash for builds
  • Architecture comparison
  • Clear separation of concerns

3. Example Test

rust-tests/tests/add_column_test.rs:

  • Demonstrates SQLx testing patterns
  • Tests eql_v2.add_column() function
  • Shows assertion patterns, setup/teardown
  • Async/await patterns

Key Insights from Documentation

SQLx/Rust Approach

Pros:

  • Type-safe database access
  • Modern async/await patterns
  • Good IDE support
  • Connection pooling

Cons:

  • Slow compile times (30s+ for test changes)
  • Overkill for testing SQL functions
  • Type system doesn't help much (SQL is dynamic)
  • Smaller PostgreSQL testing ecosystem

pgTAP Approach

Pros:

  • SQL-native, no impedance mismatch
  • Tests run IN the database
  • Designed specifically for PostgreSQL extensions
  • Fast feedback loop (no compilation)
  • Industry standard (used by PostgreSQL core)

Cons:

  • Less familiar to Rust developers
  • SQL-based testing may be unfamiliar

Comparison to PR #135

PR #135 implements pgTAP testing with:

  • 91 pgTAP tests (structure + functionality)
  • Docker integration
  • Test runner scripts

This PR proposes SQLx/Rust with:

  • Rust test infrastructure
  • 1 example test showing patterns
  • Comprehensive framework comparison documentation

Files Changed

Added:

  • SQLX_TESTING_APPROACH.md - Rationale and architecture
  • TESTING_FRAMEWORK_COMPARISON.md - Comprehensive framework analysis
  • rust-tests/ - Complete Rust testing infrastructure
    • Cargo.toml, README.md, run-tests.sh
    • Example test: add_column_test.rs

Removed (from pgTAP PR):

  • tasks/test-pgtap.sh
  • tests/Dockerfile.pgtap
  • tests/install_pgtap.sql
  • tests/pgtap/ directory

Purpose of This PR

This is an experimental/evaluation branch meant to:

  1. Document the SQLx testing approach
  2. Provide comprehensive framework comparison
  3. Enable informed decision-making
  4. Show working SQLx test examples

Recommendation

The documentation in this PR suggests pgTAP may be the better choice for EQL because:

  • It's SQL-native (matches the domain)
  • Faster feedback loop
  • Industry standard for PostgreSQL extensions
  • No compilation overhead

However, SQLx could be valuable if:

  • Team is primarily Rust-focused
  • Need integration with other Rust tooling
  • Want type-safe query building

Next Steps

Review the documentation and example code, then decide:

  1. Adopt pgTAP approach (PR Add pgTAP testing infrastructure #135)
  2. Adopt SQLx approach (this PR)
  3. Hybrid: Use both for different test types
  4. Continue with current bash-based testing

Related

This prototype demonstrates a simpler approach to testing EQL:
- Load pre-built SQL from release/cipherstash-encrypt.sql
- Use SQLx for ergonomic, type-safe test assertions
- Keep dependencies in SQL (-- REQUIRE: comments)
- Leverage existing bash build system for dependency resolution

Benefits over component system:
- No 200+ line trait/macro machinery needed
- Single source of truth (dependencies in SQL, not duplicated in Rust)
- Better test ergonomics (SQLx vs manual postgres)
- Simpler architecture (bash build + SQLx tests)

Files added:
- rust-tests/ - SQLx test project
  - src/lib.rs - Test setup helpers (load built SQL)
  - tests/add_column_test.rs - Example tests
  - run-tests.sh - Test runner
- SQLX_TESTING_APPROACH.md - Architecture comparison and rationale
- rust-tests/README.md - Usage guide

This approach eliminates the need for the Rust component system by:
1. Using existing bash + tsort for dependency resolution
2. Loading pre-built SQL in tests (not individual files)
3. Testing against complete EQL installation

To try it:
  mise run build
  cd rust-tests && ./run-tests.sh
…sions

Compares pgTAP, Python+pytest, TypeScript+Deno, and Rust+SQLx for testing EQL.

Key findings:
- pgTAP is the best fit: SQL-native, fast feedback, designed for PG extensions
- Python+pytest is excellent for complex orchestration and data validation
- Rust+SQLx is overkill: slow compile times, type system doesn't help much

Includes:
- Code examples for each framework
- Detailed pros/cons analysis
- Comparison matrix across 12 dimensions
- Decision framework based on team/project needs
- Recommendation: Use pgTAP for SQL-focused tests

The core insight: For testing SQL, use SQL. Rust's type system provides
minimal benefit when testing dynamic database operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant