Skip to content

Commit

Permalink
Merge pull request #76 from hiterm/switch-test-by-feature
Browse files Browse the repository at this point in the history
Switch tests by feature flag
  • Loading branch information
hiterm authored Sep 5, 2024
2 parents d622a96 + 97a0908 commit f3b68ac
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- run: pg_isready
- run: sudo -u postgres psql --command="CREATE USER bookshelf WITH SUPERUSER PASSWORD 'password'" --command="\du" postgres
- run: sudo -u postgres createdb --owner=bookshelf bookshelf
- run: cargo test -- --include-ignored
- run: cargo test --all-features

test-image-building:
name: Test Image Building
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "2.0.12"
edition = "2021"
default-run = "bookshelf-api"

[features]
test-with-database = []

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
4 changes: 1 addition & 3 deletions src/infrastructure/author_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl InternalAuthorRepository {
}
}

#[cfg(feature = "test-with-database")]
#[cfg(test)]
mod tests {

Expand All @@ -165,7 +166,6 @@ mod tests {
use super::*;

#[sqlx::test]
#[ignore] // Depends on PostgreSQL
async fn create_and_find_by_id(pool: PgPool) -> anyhow::Result<()> {
let user_repository = PgUserRepository::new(pool.clone());
let author_repository = PgAuthorRepository::new(pool.clone());
Expand All @@ -185,7 +185,6 @@ mod tests {
}

#[sqlx::test]
#[ignore] // Depends on PostgreSQL
async fn create_and_find_all(pool: PgPool) -> anyhow::Result<()> {
let user_repository = PgUserRepository::new(pool.clone());
let author_repository = PgAuthorRepository::new(pool.clone());
Expand All @@ -211,7 +210,6 @@ mod tests {
}

#[sqlx::test]
#[ignore] // Depends on PostgreSQL
async fn create_and_find_by_ids_as_hash_map(pool: PgPool) -> anyhow::Result<()> {
let user_repository = PgUserRepository::new(pool.clone());
let author_repository = PgAuthorRepository::new(pool.clone());
Expand Down
5 changes: 1 addition & 4 deletions src/infrastructure/book_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ impl InternalBookRepository {
}
}

#[cfg(feature = "test-with-database")]
#[cfg(test)]
mod tests {

Expand All @@ -423,7 +424,6 @@ mod tests {
};

#[sqlx::test]
#[ignore] // Depends on PostgreSQL
async fn test_create_and_find_by_id(pool: PgPool) -> anyhow::Result<()> {
let user_repository = PgUserRepository::new(pool.clone());
let author_repository = PgAuthorRepository::new(pool.clone());
Expand All @@ -445,7 +445,6 @@ mod tests {
}

#[sqlx::test]
#[ignore] // Depends on PostgreSQL
async fn test_create_and_find_all(pool: PgPool) -> anyhow::Result<()> {
let user_repository = PgUserRepository::new(pool.clone());
let author_repository = PgAuthorRepository::new(pool.clone());
Expand Down Expand Up @@ -478,7 +477,6 @@ mod tests {
}

#[sqlx::test]
#[ignore] // Depends on PostgreSQL
async fn test_update(pool: PgPool) -> anyhow::Result<()> {
// setup
let user_repository = PgUserRepository::new(pool.clone());
Expand Down Expand Up @@ -512,7 +510,6 @@ mod tests {
}

#[sqlx::test]
#[ignore] // Depends on PostgreSQL
async fn test_delete(pool: PgPool) -> anyhow::Result<()> {
let user_repository = PgUserRepository::new(pool.clone());
let author_repository = PgAuthorRepository::new(pool.clone());
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/user_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ impl InternalUserRepository {
}
}

#[cfg(feature = "test-with-database")]
#[cfg(test)]
mod tests {
use super::*;

#[sqlx::test]
#[ignore] // Depends on PostgreSQL
async fn test_user_repository(pool: PgPool) -> anyhow::Result<()> {
dotenv::dotenv().ok();

Expand Down

0 comments on commit f3b68ac

Please sign in to comment.