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 c913dcc commit 4dca18d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
21 changes: 20 additions & 1 deletion repology-webapp/tests/integration_tests/legacy_redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@ use sqlx::PgPool;
use repology_webapp_test_utils::check_response;

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_legacy_redirects(pool: PgPool) {
async fn test_version_only_for_repo(pool: PgPool) {
check_response!(pool, "/badge/version-only-for-repo/foo/bar.svg", status MOVED_PERMANENTLY, header_value "location" "/badge/version-for-repo/foo/bar.svg");
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_version_only_for_repo_with_title(pool: PgPool) {
check_response!(pool, "/badge/version-only-for-repo/foo/bar.svg?header=baz", status MOVED_PERMANENTLY, header_value "location" "/badge/version-for-repo/foo/bar.svg?header=baz");
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_project_root(pool: PgPool) {
check_response!(pool, "/project/zsh", status MOVED_PERMANENTLY, header_value "location" "/project/zsh/versions");
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_metapackage(pool: PgPool) {
check_response!(pool, "/metapackage/zsh", status MOVED_PERMANENTLY, header_value "location" "/project/zsh/versions");
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_metapackage_versions(pool: PgPool) {
check_response!(pool, "/metapackage/zsh/versions", status MOVED_PERMANENTLY, header_value "location" "/project/zsh/versions");
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_metapackage_packages(pool: PgPool) {
check_response!(pool, "/metapackage/zsh/packages", status MOVED_PERMANENTLY, header_value "location" "/project/zsh/packages");
}
22 changes: 21 additions & 1 deletion repology-webapp/tests/integration_tests/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,31 @@ use repology_webapp_test_utils::check_response;
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "common_packages", "log_data")
)]
async fn test_log(pool: PgPool) {
async fn test_nonexistent(pool: PgPool) {
check_response!(
pool,
"/log/10",
status NOT_FOUND
);
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "common_packages", "log_data")
)]
async fn test_invalid_id(pool: PgPool) {
check_response!(
pool,
"/log/foo",
status BAD_REQUEST
);
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "common_packages", "log_data")
)]
async fn test_ongoing(pool: PgPool) {
check_response!(
pool,
"/log/1",
Expand All @@ -29,6 +42,13 @@ async fn test_log(pool: PgPool) {
html_ok "allow_empty_tags,warnings_fatal",
contains "ongoing"
);
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "common_packages", "log_data")
)]
async fn test_finished(pool: PgPool) {
check_response!(
pool,
"/log/2",
Expand Down
22 changes: 21 additions & 1 deletion repology-webapp/tests/snapshot_tests/legacy_redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,35 @@ use sqlx::PgPool;
use super::uri_snapshot_test;

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_legacy_redirects(pool: PgPool) {
async fn test_version_only_for_repo(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/badge/version-only-for-repo/foo/bar.svg").await;
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_version_only_for_repo_with_title(pool: PgPool) {
uri_snapshot_test(
pool.clone(),
"/badge/version-only-for-repo/foo/bar.svg?header=baz",
)
.await;
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_project_root(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/project/zsh").await;
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_metapackage(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/metapackage/zsh").await;
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_metapackage_versions(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/metapackage/zsh/versions").await;
}

#[sqlx::test(migrator = "repology_common::MIGRATOR")]
async fn test_metapackage_packages(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/metapackage/zsh/packages").await;
}
23 changes: 22 additions & 1 deletion repology-webapp/tests/snapshot_tests/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,30 @@ use super::uri_snapshot_test;
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "common_packages", "log_data")
)]
async fn test_log(pool: PgPool) {
async fn test_nonexistent(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/log/10").await;
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "common_packages", "log_data")
)]
async fn test_invalid_id(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/log/foo").await;
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "common_packages", "log_data")
)]
async fn test_ongoing(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/log/1").await;
}

#[sqlx::test(
migrator = "repology_common::MIGRATOR",
fixtures("common_repositories", "common_packages", "log_data")
)]
async fn test_finished(pool: PgPool) {
uri_snapshot_test(pool.clone(), "/log/2").await;
}

0 comments on commit 4dca18d

Please sign in to comment.