Skip to content

Commit

Permalink
feat: auto-load .env in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe Spellman committed Feb 21, 2024
1 parent be4a63a commit c98c77a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
17 changes: 17 additions & 0 deletions test.env
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions tests/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 4 additions & 14 deletions tests/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,14 @@ struct AuthenticatedUser {
token: String,
}

#[derive(Debug, Default, Copy, Clone, Parameter)]
#[derive(Debug, Default, Copy, Clone, Parameter, strum::EnumString)]
#[param(name = "vote-type", regex = "upvote|downvote")]
#[strum(ascii_case_insensitive)]
enum VoteType {
#[default]
Upvote,
Downvote,
}

impl FromStr for VoteType {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"upvote" => Self::Upvote,
"downvote" => Self::Downvote,
_ => return Err(format!("invalid vote type {s}")),
})
}
}

impl From<VoteType> for bool {
fn from(value: VoteType) -> Self {
match value {
Expand Down Expand Up @@ -265,6 +253,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()
Expand Down

0 comments on commit c98c77a

Please sign in to comment.