From 50475a0fb637bf8adc3cc0f08158ebbf893babf1 Mon Sep 17 00:00:00 2001 From: Zoe Spellman Date: Wed, 21 Feb 2024 00:24:48 -0800 Subject: [PATCH] feat: auto-load .env in tests --- test.env | 17 +++++++++++++++++ tests/authentication.rs | 2 ++ tests/chart.rs | 2 ++ tests/voting.rs | 4 +++- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test.env diff --git a/test.env b/test.env new file mode 100644 index 00000000..0a385dbd --- /dev/null +++ b/test.env @@ -0,0 +1,17 @@ +APP_ENV=dev +APP_HOST=0.0.0.0 +APP_JWT_SECRET=deadbeef +APP_LOG_LEVEL=info +APP_NAME=ratings +APP_PORT=8080 +# Update this with some real PostgreSQL details +APP_POSTGRES_URI=postgresql://migration_user:strongpassword@localhost:5433/ratings +APP_MIGRATION_POSTGRES_URI=postgresql://migration_user:strongpassword@localhost:5433/ratings + +DOCKER_POSTGRES_USER=postgres +DOCKER_POSTGRES_PASSWORD=@1234 +DOCKER_MIGRATION_USER=migration_user +DOCKER_MIGRATION_PASSWORD=strongpassword +DOCKER_SERVICE_USER=service +DOCKER_SERVICE_PASSWORD=covfefe!1 +DOCKER_RATINGS_DB=ratings diff --git a/tests/authentication.rs b/tests/authentication.rs index 1c920e98..32e62a88 100644 --- a/tests/authentication.rs +++ b/tests/authentication.rs @@ -94,6 +94,8 @@ async fn no_double_auth(world: &mut AuthenticationWorld) { #[tokio::main] async fn main() { + dotenv::from_filename("test.env").ok(); + AuthenticationWorld::cucumber() .repeat_skipped() .init_tracing() diff --git a/tests/chart.rs b/tests/chart.rs index ef3f5055..7bda685b 100644 --- a/tests/chart.rs +++ b/tests/chart.rs @@ -240,6 +240,8 @@ async fn clear_db() { #[tokio::main] async fn main() { + dotenv::from_filename("test.env").ok(); + ChartWorld::cucumber() .before(|_, _, _, _| clear_db().boxed_local()) .repeat_failed() diff --git a/tests/voting.rs b/tests/voting.rs index 25fa6863..ee77027e 100644 --- a/tests/voting.rs +++ b/tests/voting.rs @@ -16,7 +16,7 @@ struct AuthenticatedUser { token: String, } -#[derive(Debug, Default, Copy, Clone, Parameter)] +#[derive(Debug, Default, Copy, Clone, Parameter, strum::)] #[param(name = "vote-type", regex = "upvote|downvote")] enum VoteType { #[default] @@ -265,6 +265,8 @@ async fn check_upvote(world: &mut VotingWorld, direction: Direction) { #[tokio::main] async fn main() { + dotenv::from_filename("test.env").ok(); + VotingWorld::cucumber() .repeat_skipped() .init_tracing()