-
Notifications
You must be signed in to change notification settings - Fork 0
feat(testing): add SQLx/Rust test framework infrastructure #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Implement pgTAP test framework to provide industry-standard PostgreSQL testing capabilities alongside existing custom assertion helpers. Changes: - Add pgTAP to Docker containers (PostgreSQL 14-17) - Create pgTAP test runner script (tasks/test-pgtap.sh) - Add structure tests: schema, types, functions, operators - Add functionality tests: equality operators - Update docker-compose.yml to build custom images with pgTAP Structure tests verify EQL schema elements exist with correct signatures. Functionality tests validate encrypted data equality operations using pgTAP assertions. This implements Tasks 1-3 from docs/pgtap-implementation-plan.md.
Improvements based on plan review: - Add Task 0.5: Verify prerequisites (Rust, mise, Docker, psql) - Add Success Criteria section with clear metrics and rollback strategy - Improve Task 3, Step 3: Add function signature verification for selectors - Enhance Task 12: Better error messages in Rust helper with unwrap_or_else - Document Task 4: Add fixture dependency comments (array_data → encrypted_json) - Add test coverage metric: 16 tests from 2 source files These changes improve plan clarity, verification steps, and error handling while maintaining the POC scope.
0e53726 to
fed5efc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks like a big uplift.
Left some comments/questions on the code.
One thing I found confusing was the tests dir - which in a cargo project is usually for the integration tests of the containing crate, but tests actually defines a new crate called eql_tests. Not a hill I'll die on but it confused me and also Claude.
| let rows = sqlx::query(&self.sql) | ||
| .fetch_all(self.pool) | ||
| .await | ||
| .unwrap_or_else(|_| panic!("Query failed: {}", self.sql)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The panic message for query failures could include the error:
// Current
.unwrap_or_else(|_| panic!("Query failed: {}", self.sql)); // Suggestion
.unwrap_or_else(|e| panic!("Query failed: {}\nError: {}", self.sql, e));
tests/sqlx/README.md
Outdated
| ✅ **Like-for-Like Migration: Complete** (40/40 SQL assertions ported) | ||
|
|
||
| - Equality operators: 16/16 (HMAC + Blake3, operators + functions + JSONB) | ||
| - JSONB functions: 24/24 (arrays, paths, structure validation, encrypted selectors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this accurate? I can't find any tests.
tests/sqlx/README.md
Outdated
| ### Test Count | ||
|
|
||
| - **Total**: 35 tests (34 functional + 1 helper) | ||
| - **JSONB**: 19 tests | ||
| - **Equality**: 15 tests | ||
| - **Helpers**: 1 test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a hallucination or due to not committing the actual tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep yep. Good catch.
I split the PRS. Docs have been included in this one.
Will fix
fed5efc to
f54dce0
Compare
Add comprehensive Rust/SQLx testing infrastructure to replace pgTAP: **Core Framework:** - Create tests/sqlx crate with fluent assertion API - Add selector constants to eliminate magic string literals - Implement query assertion builder for ergonomic test writing **Test Infrastructure:** - Add SQLx migrations for EQL installation and test helpers - Add SQL fixtures for test data seeding - Configure Cargo workspace integration **Tooling & Scripts:** - Add mise tasks for test execution and coverage tracking - Add assertion counting and comparison tools - Add function call tracking for coverage analysis - Add test inventory generator - Add master coverage check script **Configuration:** - Update Docker Compose with track_functions enabled - Add generated migration files to gitignore - Update mise.toml with Rust test tasks **Migration:** - Remove pgTAP testing infrastructure (Dockerfile, tests, scripts) - Add SQL-to-SQLx migration guide documentation - Add assertion count and test inventory docs This infrastructure enables writing Rust tests with SQLx queries instead of pgTAP, providing better IDE support, type safety, and debugging.
f54dce0 to
7d036c7
Compare
|
@freshtonic |
Summary
This PR introduces a comprehensive Rust/SQLx testing infrastructure to replace the existing pgTAP framework. This is the foundation for migrating EQL tests to a more maintainable, type-safe testing approach.
Part 1 of 3 in the test migration series:
What's Changed
Core Test Framework
tests/sqlx/): New Rust test crate with SQLx integrationTooling & Scripts
Configuration Updates
track_functionsfor coverage trackingTesting Infrastructure
The new framework provides: