-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webapp: Implement basic snapshot tests (#75)
This was supposed to work on production data extract, but it turned out that there's no easy way to extract data conditionally and put it in for of sql insert statements. So instead, just take fixtures and urls from our integration tests and run snapshot testing on these. IMO it's too early to put snapshots into the repository, so use case for these tests is mostly local development, and for this purpose they are hidden between snapshot-tests feature, and snapshots directory is added go .gitignore. To use them, just run `make snapshot-tests` before and after your changes. While here, switch integration test fixtures to fixed timestamps to make them suitable for snapshots.
- Loading branch information
Showing
27 changed files
with
891 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/target | ||
/repology-webapp/tests/snapshot_tests/snapshots |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
repology-webapp/tests/integration_tests/fixtures/log_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
INSERT INTO runs(id, type, repository_id, status, start_ts, finish_ts, num_lines, num_warnings, num_errors) VALUES | ||
(1, 'fetch', 1, 'running', now() - interval '1h', NULL, NULL, NULL, NULL), | ||
(2, 'fetch', 1, 'successful', now() - interval '1h', now() + interval '5 second', 1, 2, 3); | ||
(1, 'fetch', 1, 'running', '2024-01-01 00:00:00', NULL, NULL, NULL, NULL), | ||
(2, 'fetch', 1, 'successful', '2024-01-01 00:00:00', '2124-01-01 00:00:00', 1, 2, 3); | ||
|
||
INSERT INTO log_lines(run_id, lineno, timestamp, severity, message) VALUES | ||
(1, 1, now() + interval '5 second', 'notice', 'Hello, world!'), | ||
(1, 2, now() + interval '5 second', 'warning', 'Hello, world!'), | ||
(1, 3, now() + interval '5 second', 'error', 'Hello, world!'), | ||
(2, 1, now() + interval '5 second', 'notice', 'Hello, world!'), | ||
(2, 2, now() + interval '5 second', 'warning', 'Hello, world!'), | ||
(2, 3, now() + interval '5 second', 'error', 'Hello, world!'); | ||
(1, 1, '2024-01-01 00:00:01', 'notice', 'Hello, world!'), | ||
(1, 2, '2024-01-01 00:00:02', 'warning', 'Hello, world!'), | ||
(1, 3, '2024-01-01 00:00:03', 'error', 'Hello, world!'), | ||
(2, 1, '2024-01-01 00:00:01', 'notice', 'Hello, world!'), | ||
(2, 2, '2024-01-01 00:00:02', 'warning', 'Hello, world!'), | ||
(2, 3, '2024-01-01 00:00:03', 'error', 'Hello, world!'); |
9 changes: 5 additions & 4 deletions
9
repology-webapp/tests/integration_tests/fixtures/maintainer_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
INSERT INTO maintainers(id, maintainer, orphaned_at) VALUES | ||
(1, '[email protected]', now() - interval '7 day'); | ||
(1, '[email protected]', '2024-01-01 00:00:00'), | ||
(2, '[email protected]', '2124-01-01 00:00:00'); | ||
|
||
INSERT INTO maintainers(id, maintainer, num_packages, num_projects, counts_per_repo, num_projects_per_category) VALUES | ||
(2, '[email protected]', 10, 10, '{"freebsd":[10,11,12,13,14,15]}'::jsonb, '{"games":10}'::jsonb), | ||
(3, 'fallback-mnt-foo@repology', 1, 1, '{"freebsd":[1,1,1,1,1,1]}'::jsonb, '{"games":10}'::jsonb), | ||
(4, '[email protected]', 10, 10, '{"freebsd":[10,11,12,13,14]}'::jsonb, '{"games":10}'::jsonb); | ||
(3, '[email protected]', 10, 10, '{"freebsd":[10,11,12,13,14,15]}'::jsonb, '{"games":10}'::jsonb), | ||
(4, 'fallback-mnt-foo@repology', 1, 1, '{"freebsd":[1,1,1,1,1,1]}'::jsonb, '{"games":10}'::jsonb), | ||
(5, '[email protected]', 10, 10, '{"freebsd":[10,11,12,13,14]}'::jsonb, '{"games":10}'::jsonb); |
13 changes: 7 additions & 6 deletions
13
repology-webapp/tests/integration_tests/fixtures/maintainer_feed_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
INSERT INTO maintainer_repo_metapackages_events(repository_id, maintainer_id, ts, metapackage_id, type, data) VALUES | ||
(1, 1, now() + interval '5 second', 1, 'added', '{}'::jsonb), | ||
(1, 1, now() + interval '5 second', 1, 'removed', '{}'::jsonb), | ||
(1, 1, now() + interval '5 second', 1, 'uptodate', '{"version": "111"}'::jsonb), | ||
(1, 1, now() + interval '5 second', 1, 'outdated', '{"version": "222", "newest_versions": ["333", "444"]}'::jsonb), | ||
(1, 1, now() + interval '5 second', 1, 'outdated', '{"version": "555"}'::jsonb), | ||
(1, 1, now() + interval '5 second', 1, 'ignored', '{"version": "666"}'::jsonb); | ||
-- same time as we're also testing stable ordering by type | ||
(1, 1, '2124-01-01 00:00:00', 1, 'added', '{}'::jsonb), | ||
(1, 1, '2124-01-01 00:00:00', 1, 'removed', '{}'::jsonb), | ||
(1, 1, '2124-01-01 00:00:00', 1, 'uptodate', '{"version": "111"}'::jsonb), | ||
(1, 1, '2124-01-01 00:00:00', 1, 'outdated', '{"version": "222", "newest_versions": ["333", "444"]}'::jsonb), | ||
(1, 1, '2124-01-01 00:00:00', 1, 'outdated', '{"version": "555"}'::jsonb), | ||
(1, 1, '2124-01-01 00:00:00', 1, 'ignored', '{"version": "666"}'::jsonb); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
repology-webapp/tests/integration_tests/fixtures/repository_feed_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
INSERT INTO repository_events(repository_id, ts, metapackage_id, type, data) VALUES | ||
(1, now() + interval '5 second', 1, 'added', '{}'::jsonb), | ||
(1, now() + interval '5 second', 1, 'removed', '{}'::jsonb), | ||
(1, now() + interval '5 second', 1, 'uptodate', '{"version": "111"}'::jsonb), | ||
(1, now() + interval '5 second', 1, 'outdated', '{"version": "222", "newest_versions": ["333", "444"]}'::jsonb), | ||
(1, now() + interval '5 second', 1, 'outdated', '{"version": "555"}'::jsonb), | ||
(1, now() + interval '5 second', 1, 'ignored', '{"version": "666"}'::jsonb); | ||
-- same time as we're also testing stable ordering by type | ||
(1, '2124-01-01 00:00:00', 1, 'added', '{}'::jsonb), | ||
(1, '2124-01-01 00:00:00', 1, 'removed', '{}'::jsonb), | ||
(1, '2124-01-01 00:00:00', 1, 'uptodate', '{"version": "111"}'::jsonb), | ||
(1, '2124-01-01 00:00:00', 1, 'outdated', '{"version": "222", "newest_versions": ["333", "444"]}'::jsonb), | ||
(1, '2124-01-01 00:00:00', 1, 'outdated', '{"version": "555"}'::jsonb), | ||
(1, '2124-01-01 00:00:00', 1, 'ignored', '{"version": "666"}'::jsonb); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,14 @@ async fn test_maintainer(pool: PgPool) { | |
html_ok "allow_empty_tags,warnings_fatal", | ||
contains "Gone maintainer", | ||
); | ||
check_response!( | ||
pool, | ||
"/maintainer/[email protected]", | ||
status NOT_FOUND, | ||
content_type "text/html", | ||
html_ok "allow_empty_tags,warnings_fatal", | ||
contains "Gone maintainer", | ||
); | ||
|
||
check_response!( | ||
pool, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-FileCopyrightText: Copyright 2024 Dmitry Marakasov <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#![cfg(feature = "snapshot-tests")] | ||
#![feature(coverage_attribute)] | ||
#![coverage(off)] | ||
|
||
mod snapshot_tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-FileCopyrightText: Copyright 2024 Dmitry Marakasov <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
use sqlx::PgPool; | ||
|
||
use super::uri_snapshot_test; | ||
|
||
#[sqlx::test(migrator = "repology_common::MIGRATOR", fixtures("api_data"))] | ||
async fn test_api_v1_project(pool: PgPool) { | ||
uri_snapshot_test(pool.clone(), "/api/v1/project/nonexistent").await; | ||
uri_snapshot_test(pool.clone(), "/api/v1/project/full").await; | ||
uri_snapshot_test(pool.clone(), "/api/v1/project/minimal").await; | ||
uri_snapshot_test(pool.clone(), "/api/v1/project/vulnerable").await; | ||
} | ||
|
||
#[sqlx::test( | ||
migrator = "repology_common::MIGRATOR", | ||
fixtures("common_repositories", "projects_data") | ||
)] | ||
async fn test_api_v1_projects(pool: PgPool) { | ||
uri_snapshot_test(pool.clone(), "/api/v1/projects/pkg_foo/").await; | ||
uri_snapshot_test(pool.clone(), "/api/v1/projects/?search=bar").await; | ||
} |
Oops, something went wrong.