Skip to content
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

feat: Add support for TestContainers (pgsql + redis modules) #503

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

spencewenski
Copy link
Member

Add support for TestContainers to make it easy to set up independent test environments to allow running tests in parallel without risk of cross-contamination even if they touch the DB.

TestContainers support is behind the test-containers flag. When the flag is enabled, the consumer can enable TestContainers for the DB and Sidekiq Redis in the AppConfig, in which case a TestContainer instance will be create when building the AppContext, and the URI in the AppConfig will be updated to match that of the TestContainer instance.

Additionally, a new method was added to AppConfig to allow consumers to create it themselves. This would allow consumers more control over the config, including manually creating a TestContainer instance and updating the URI of a field in the AppConfig before loading the application.

Finally, a new app::init_state method was added to allow getting access to a real AppState instance in tests. This method performs most of the setup of the app without actually running the app. This is similar but slightly different to the existing app::prepare method, and is intended to only be used in tests.

Closes #500

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 0% with 211 lines in your changes missing coverage. Please review.

Project coverage is 40.69%. Comparing base (357042a) to head (67222c9).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/app/mod.rs 0.00% 131 Missing ⚠️
src/app/context.rs 0.00% 67 Missing ⚠️
src/config/mod.rs 0.00% 12 Missing ⚠️
src/api/core/health.rs 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/config/database/mod.rs 89.28% <ø> (-0.37%) ⬇️
src/config/service/worker/sidekiq/mod.rs 82.35% <ø> (-0.99%) ⬇️
src/service/runner.rs 0.00% <ø> (ø)
src/api/core/health.rs 0.00% <0.00%> (ø)
src/config/mod.rs 34.55% <0.00%> (-0.78%) ⬇️
src/app/context.rs 13.63% <0.00%> (-5.85%) ⬇️
src/app/mod.rs 0.00% <0.00%> (ø)

... and 45 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 357042a...67222c9. Read the comment docs.

Add support for TestContainers to make it easy to set up independent
test environments to allow running tests in parallel without risk of
cross-contamination even if they touch the DB.

TestContainers support is behind the `test-containers` flag. When the
flag is enabled, the consumer can enable TestContainers for the DB and
Sidekiq Redis in the `AppConfig`, in which case a TestContainer
instance will be create when building the `AppContext`, and the URI in
the `AppConfig` will be updated to match that of the TestContainer
instance.

Additionally, a new method was added to `AppConfig` to allow consumers
to create it themselves. This would allow consumers more control over
the config, including manually creating a TestContainer instance and
updating the URI of a field in the `AppConfig` before loading the
application.

Finally, a new `app::init_state` method was added to allow getting
access to a real `AppState` instance in tests. This method performs most
of the setup of the app without actually running the app. This is
similar but slightly different to the existing `app::prepare` method,
and is intended to only be used in tests.

Closes #500
@spencewenski spencewenski merged commit 4825937 into main Nov 12, 2024
17 of 19 checks passed
@spencewenski spencewenski deleted the test-containers branch November 12, 2024 09:10
@github-actions github-actions bot mentioned this pull request Nov 12, 2024
spencewenski added a commit that referenced this pull request Nov 13, 2024
## 🤖 New release
* `roadster`: 0.6.16 -> 0.6.17 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.6.17](roadster-v0.6.16...roadster-v0.6.17)
- 2024-11-12

### Added

- Add support for TestContainers (pgsql + redis modules)
([#503](#503))

### Other

- Update `thiserror` to 2.x
([#499](#499))
- Update `validator` crate
([#497](#497))
- Use justfile scripts for pre-commit/pre-push hooks
([#494](#494))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Spencer Ferris <[email protected]>
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.

TestContainers for testing?
1 participant