-
-
Notifications
You must be signed in to change notification settings - Fork 37
refactor!: use TestContainers #458
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
base: master
Are you sure you want to change the base?
Conversation
|
| Branch | test-containers |
| Testbed | github-ubuntu-latest |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result microseconds (µs) (Result Δ%) | Upper Boundary microseconds (µs) (Limit %) |
|---|---|---|---|
| empty_router/empty_router | 📈 view plot 🚷 view threshold | 6,730.90 µs(+13.36%)Baseline: 5,937.82 µs | 7,140.99 µs (94.26%) |
| json_api/json_api | 📈 view plot 🚷 view threshold | 1,052.10 µs(+3.57%)Baseline: 1,015.79 µs | 1,162.89 µs (90.47%) |
| nested_routers/nested_routers | 📈 view plot 🚷 view threshold | 972.02 µs(+3.84%)Baseline: 936.08 µs | 1,065.51 µs (91.23%) |
| single_root_route/single_root_route | 📈 view plot 🚷 view threshold | 935.89 µs(+4.31%)Baseline: 897.23 µs | 1,023.90 µs (91.40%) |
| single_root_route_burst/single_root_route_burst | 📈 view plot 🚷 view threshold | 17,985.00 µs(+2.35%)Baseline: 17,572.13 µs | 20,842.61 µs (86.29%) |
2478966 to
4d25196
Compare
b3161ea to
1026eda
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.
Pull request overview
This pull request refactors the testing framework to use Testcontainers instead of manually spinning up Docker containers. The change improves test isolation and makes it easier to run tests, but comes with increased resource usage and a significantly larger dependency footprint.
Changes:
- Replaced manual Docker Compose setup with Testcontainers for all external test dependencies (PostgreSQL, MariaDB/MySQL, Redis, Selenium WebDriver)
- Removed the
testfeature from thefullfeature set and made it an optional dependency - Updated CI/CD workflows to remove Docker Compose startup steps
- Added comprehensive WebDriver management through
TestServerWithWebDriverwrapper - Modified test ignore messages to be more accurate
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| justfile | Removed Docker Compose commands from test targets, simplified test execution |
| cot/tests/admin.rs | Updated WebDriver integration to use Testcontainers, improved test function signatures |
| cot/src/test.rs | Major refactoring to use Testcontainers for databases, Redis, and Selenium; added TestServerWithWebDriver and TestWebDriver types |
| cot/src/session/store/redis.rs | Updated Redis tests to use containerized Redis instances |
| cot/src/cache/store/redis.rs | Updated cache tests to use containerized Redis instances |
| cot/Cargo.toml | Added testcontainers dependencies, removed test from full feature |
| cot-cli/src/project_template/Cargo.toml.template | Added test feature to dev-dependencies for new projects |
| compose.yml | Deleted - no longer needed for testing |
| clippy.toml | Added "WebDriver" to valid identifiers |
| README.md | Updated test instructions to remove Docker Compose requirement |
| CONTRIBUTING.md | Updated test documentation to reflect Testcontainers usage |
| .github/workflows/rust.yml | Removed Docker Compose setup steps from CI/CD |
| Cargo.lock | Added numerous new dependencies for testcontainers ecosystem |
| cot-macros/tests/ui/derive_into_response_missing_trait_impl.stderr | Minor compiler output formatting change |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// function, you can set the `COT_TEST_SERVER_HOST` environment variable | ||
| /// or call [`Self::set_host`]. | ||
| /// |
Copilot
AI
Feb 2, 2026
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 documentation references a non-existent method Self::set_host. Either this method needs to be implemented or the reference should be removed from the documentation.
| /// function, you can set the `COT_TEST_SERVER_HOST` environment variable | |
| /// or call [`Self::set_host`]. | |
| /// | |
| /// function, you can set the `COT_TEST_SERVER_HOST` environment variable. | |
| /// | |
| /// |
| .raw(&format!( | ||
| "SELECT pg_terminate_backend(pg_stat_activity.pid) \ | ||
| FROM pg_stat_activity \ | ||
| WHERE pg_stat_activity.datname = '{db_name}' \ | ||
| AND pid <> pg_backend_pid()" | ||
| )) |
Copilot
AI
Feb 2, 2026
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.
SQL injection vulnerability: the database name is interpolated directly into the SQL query without proper escaping or parameterization. Although test names are typically controlled, this creates a security risk if a malicious test name is used. Consider using PostgreSQL identifier quoting (e.g., wrapping the identifier in double quotes and escaping any double quotes within it), or using a parameterized query if the database driver supports it for DDL operations.
| )) | ||
| .await?; | ||
|
|
||
| database.raw(&format!("DROP DATABASE {db_name}")).await?; |
Copilot
AI
Feb 2, 2026
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.
SQL injection vulnerability: the database name is interpolated directly into the SQL query without proper escaping or parameterization. Although test names are typically controlled, this creates a security risk if a malicious test name is used. Consider using proper identifier quoting or parameterized queries.
| } => { | ||
| let database = Database::new(format!("{db_url}/mysql")).await?; | ||
|
|
||
| database.raw(&format!("DROP DATABASE {db_name}")).await?; |
Copilot
AI
Feb 2, 2026
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.
SQL injection vulnerability: the database name is interpolated directly into the SQL query without proper escaping or parameterization. Although test names are typically controlled, this creates a security risk if a malicious test name is used. Consider using proper identifier quoting or parameterized queries.
| container is automatically started using Testcontainers. | ||
|
|
||
| Alternatively, you can run the tests with a local webdriver server. To do this, | ||
| you need to set the `WEBDRIVER_URL` environment variable to the URL of your |
Copilot
AI
Feb 2, 2026
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.
Environment variable name inconsistency: The documentation mentions WEBDRIVER_URL but the code uses COT_WEBDRIVER_URL. These should be consistent. Either update the documentation to say COT_WEBDRIVER_URL or change the code to use WEBDRIVER_URL.
| you need to set the `WEBDRIVER_URL` environment variable to the URL of your | |
| you need to set the `COT_WEBDRIVER_URL` environment variable to the URL of your |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
| let host_port = container | ||
| .get_host_port_ipv4(POSTGRES_PORT) | ||
| .await | ||
| .map_err(|e| { | ||
| TestcontainersError::new("failed to get PostgreSQL container port", e) | ||
| })?; | ||
| let host_port: u16 = host_port; |
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.
Why two let statements?
|
|
||
| #[derive(Debug, Error)] | ||
| #[error("{message}: {inner}")] | ||
| struct TestcontainersError { |
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.
nit: I know the name matches the library name, but it pains me it's not TestContainersError
| /// # Errors | ||
| /// | ||
| /// Returns an error if the container could not be started. | ||
| pub async fn with_host_port_exposure(port: u16) -> Result<Self> { |
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.
Personally, I think with_host_post_exposed is better
This changes the Cot's testing framework to use Testcontainers instead of manually spinning up Docker containers.
This change:
This comes with some drawbacks, though:
testfeature flag from thefullfeature set)Whether it's worth it - I'm leaving this for others to decide.