Skip to content

Commit

Permalink
webapp: Granularize more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Dec 24, 2024
1 parent 4dca18d commit 898c8ce
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
COVERAGE_FLAGS=-Cinstrument-coverage -Zcoverage-options=condition

snapshots:
env INSTA_UPDATE=unseen cargo test
env INSTA_UPDATE=unseen cargo test snapshot_tests

snapshots-review:
cargo instal revirew
cargo instal review

coverage:
cargo llvm-cov --features=coverage --open
Expand Down
38 changes: 37 additions & 1 deletion repology-webapp/tests/integration_tests/maintainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use repology_webapp_test_utils::check_response;
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_maintainer(pool: PgPool) {
async fn test_nonexistent(pool: PgPool) {
check_response!(
pool,
"/maintainer/[email protected]",
Expand All @@ -18,6 +18,13 @@ async fn test_maintainer(pool: PgPool) {
html_ok "allow_empty_tags,warnings_fatal",
contains "Unknown maintainer",
);
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_orphaned(pool: PgPool) {
check_response!(
pool,
"/maintainer/[email protected]",
Expand All @@ -26,6 +33,13 @@ async fn test_maintainer(pool: PgPool) {
html_ok "allow_empty_tags,warnings_fatal",
contains "Gone maintainer",
);
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_orphaned_in_future(pool: PgPool) {
check_response!(
pool,
"/maintainer/[email protected]",
Expand All @@ -34,7 +48,13 @@ async fn test_maintainer(pool: PgPool) {
html_ok "allow_empty_tags,warnings_fatal",
contains "Gone maintainer",
);
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_active(pool: PgPool) {
check_response!(
pool,
"/maintainer/[email protected]",
Expand All @@ -52,6 +72,13 @@ async fn test_maintainer(pool: PgPool) {
// not testing similar maintainers for now
// not testing projects list for now
);
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_fallback(pool: PgPool) {
check_response!(
pool,
"/maintainer/fallback-mnt-foo@repology",
Expand All @@ -63,6 +90,15 @@ async fn test_maintainer(pool: PgPool) {
// contact section
contains_not "mailto:[email protected]",
);
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_no_vuln_column(pool: PgPool) {
// Maintainer not updated for a long time, without vulnerable projects
// counter filled.
check_response!(
pool,
"/maintainer/[email protected]",
Expand Down
21 changes: 20 additions & 1 deletion repology-webapp/tests/integration_tests/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sqlx::PgPool;
use repology_webapp_test_utils::check_response;

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_repository(pool: PgPool) {
async fn test_nonexistent(pool: PgPool) {
check_response!(
pool,
"/repository/nonexistent",
Expand All @@ -16,6 +16,10 @@ async fn test_repository(pool: PgPool) {
//html_ok "allow_empty_tags,warnings_fatal",
//contains "Unknown repositry",
);
}

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_orphaned(pool: PgPool) {
check_response!(
pool,
"/repository/orphaned",
Expand All @@ -24,6 +28,10 @@ async fn test_repository(pool: PgPool) {
html_ok "allow_empty_tags,warnings_fatal",
contains "Gone repository",
);
}

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_empty(pool: PgPool) {
check_response!(
pool,
"/repository/empty",
Expand All @@ -32,6 +40,13 @@ async fn test_repository(pool: PgPool) {
html_ok "allow_empty_tags,warnings_fatal",
contains_not "Gone repository",
);
}

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_stripped(pool: PgPool) {
// test handling minimal data in database: empty metadata, and
// no used_package_link_types; in prod this case is possible
// for repositories removed long time ago
check_response!(
pool,
"/repository/stripped",
Expand All @@ -42,6 +57,10 @@ async fn test_repository(pool: PgPool) {
contains "homepage or download links",
contains "package recipes or sources",
);
}

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_normal(pool: PgPool) {
check_response!(
pool,
"/repository/good",
Expand Down
37 changes: 36 additions & 1 deletion repology-webapp/tests/snapshot_tests/maintainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,46 @@ use super::uri_snapshot_test;
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_maintainer(pool: PgPool) {
async fn test_nonexistent(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/maintainer/[email protected]").await;
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_orphaned(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/maintainer/[email protected]").await;
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_orphaned_in_future(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/maintainer/[email protected]").await;
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_active(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/maintainer/[email protected]").await;
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_fallback(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/maintainer/fallback-mnt-foo@repology").await;
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "maintainer_data")
)]
async fn test_no_vuln_column(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/maintainer/[email protected]").await;
}
18 changes: 17 additions & 1 deletion repology-webapp/tests/snapshot_tests/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,26 @@ use sqlx::PgPool;
use super::uri_snapshot_test;

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_repository(pool: PgPool) {
async fn test_nonexistent(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/repository/nonexistent").await;
}

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_orphaned(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/repository/orphaned").await;
}

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_empty(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/repository/empty").await;
}

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_stripped(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/repository/stripped").await;
}

#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("repository_data"))]
async fn test_normal(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/repository/good").await;
}

0 comments on commit 898c8ce

Please sign in to comment.