forge
Explore
Log in

Don't you dare go Hollow

Page a-l tests merge into tables and drop checks that cannot fail

Browse files at this commit

9b3e6a7b2a718fa6394d94b98ad7362069c0b0d7Ahmet Kaan GümüşParent: aeec80c
  • test
    • page a-l tests merge into tables and drop checks that cannot fail
Show full message
✅ test: page a-l tests merge into tables and drop checks that cannot fail

Test count in crates/forge-web/src/pages (a-l files) goes from 294 to 288.
Two access-check tests in ci_tests share one fixture now, the two badge
label tests share one, the df and du parser tests merge, the admin mail
stream check runs inside the admin-only test, and the signature badge
checks fold into the commit list and commit page tests.
crates/forge-web/src/pages/admin_health.rsmodified+6 -10
@@ -409,15 +409,11 @@ mod tests {
409 use super::*;409 use super::*;
410 410
411 #[test]411 #[test]
412- fn df_output_parses_to_bytes() {412+ fn df_and_du_output_parse_to_bytes() {
413- let out = "Filesystem 1024-blocks Used Available Capacity Mounted on\n/dev/sda1 1000 400 600 40% /\n";413+ let df = "Filesystem 1024-blocks Used Available Capacity Mounted on\n/dev/sda1 1000 400 600 40% /\n";
414- assert_eq!(parse_df(out), Some((1000 * 1024, 600 * 1024)));414+ assert_eq!(parse_df(df), Some((1000 * 1024, 600 * 1024)), "df");
415- assert_eq!(parse_df("garbage"), None);415+ assert_eq!(parse_df("garbage"), None, "df garbage");
416- }416+ assert_eq!(parse_du("12\t/data/repos\n"), Some(12 * 1024), "du");
417-417+ assert_eq!(parse_du(""), None, "du empty");
418- #[test]
419- fn du_output_parses_to_bytes() {
420- assert_eq!(parse_du("12\t/data/repos\n"), Some(12 * 1024));
421- assert_eq!(parse_du(""), None);
422 }418 }
423 }419 }
crates/forge-web/src/pages/admin_mail.rsmodified+3 -7
@@ -955,7 +955,7 @@ mod tests {
955 }955 }
956 956
957 #[tokio::test]957 #[tokio::test]
958- async fn the_queue_events_and_its_actions_are_admin_only() {958+ async fn the_queue_events_and_its_actions_are_admin_only_and_admins_get_the_stream() {
959 let fx = fixture().await;959 let fx = fixture().await;
960 for (method, uri) in [960 for (method, uri) in [
961 ("GET", "/admin/mail/events"),961 ("GET", "/admin/mail/events"),
@@ -981,11 +981,7 @@ mod tests {
981 .await;981 .await;
982 assert_eq!(user, 404, "{method} {uri} for a plain user");982 assert_eq!(user, 404, "{method} {uri} for a plain user");
983 }983 }
984- }984+ // An admin gets the queue event stream.
985-
986- #[tokio::test]
987- async fn an_admin_gets_the_queue_event_stream() {
988- let fx = fixture().await;
989 let request = Request::builder()985 let request = Request::builder()
990 .method("GET")986 .method("GET")
991 .uri("/admin/mail/events")987 .uri("/admin/mail/events")
@@ -993,7 +989,7 @@ mod tests {
993 .body(Body::empty())989 .body(Body::empty())
994 .expect("request");990 .expect("request");
995 let res = fx.router.handle(request).await;991 let res = fx.router.handle(request).await;
996- assert_eq!(res.status().as_u16(), 200);992+ assert_eq!(res.status().as_u16(), 200, "admin stream status");
997 let kind = res993 let kind = res
998 .headers()994 .headers()
999 .get("content-type")995 .get("content-type")
crates/forge-web/src/pages/ci_tests.rsmodified+8 -26
@@ -405,6 +405,7 @@ async fn live_events_need_the_same_access_as_the_page() {
405 let urls = [405 let urls = [
406 format!("{RUN_BASE}/runs/{}/events", run.number),406 format!("{RUN_BASE}/runs/{}/events", run.number),
407 format!("/tahinli/proj/ci/jobs/{}/events", job.id),407 format!("/tahinli/proj/ci/jobs/{}/events", job.id),
408+ format!("{RUN_BASE}/events"),
408 ];409 ];
409 for url in &urls {410 for url in &urls {
410 let anon = open(&fx.app, url, None).await;411 let anon = open(&fx.app, url, None).await;
@@ -578,19 +579,6 @@ async fn split_view_draws_the_newest_run_or_the_one_named() {
578 );579 );
579 }580 }
580 581
581-#[tokio::test]
582-async fn run_list_events_need_the_same_access_as_the_page() {
583- let dir = tempfile::tempdir().expect("tempdir");
584- let fx = fixture(dir.path()).await;
585- let url = format!("{RUN_BASE}/events");
586- let anon = open(&fx.app, &url, None).await;
587- assert_eq!(anon.status().as_u16(), 404, "anonymous");
588- let outsider = open(&fx.app, &url, Some(&cookie_for("carol-token"))).await;
589- assert_eq!(outsider.status().as_u16(), 404, "outsider");
590- let reader = open(&fx.app, &url, Some(&cookie_for("dave-token"))).await;
591- assert_eq!(reader.status().as_u16(), 200, "reader");
592-}
593-
594 /// The list stream sends nothing on connect, then one `changed` event per change of the repo.582 /// The list stream sends nothing on connect, then one `changed` event per change of the repo.
595 #[tokio::test]583 #[tokio::test]
596 async fn run_list_events_follow_repo_changes() {584 async fn run_list_events_follow_repo_changes() {
@@ -1254,7 +1242,7 @@ async fn badge_label_comes_from_the_query_job_or_workflow_name() {
1254 }1242 }
1255 1243
1256 #[tokio::test]1244 #[tokio::test]
1257-async fn badge_label_is_trimmed_and_empty_means_absent() {1245+async fn badge_label_is_trimmed_escaped_and_empty_means_absent() {
1258 let dir = tempfile::tempdir().expect("tempdir");1246 let dir = tempfile::tempdir().expect("tempdir");
1259 let fx = fixture(dir.path()).await;1247 let fx = fixture(dir.path()).await;
1260 run_with(&fx, &["build"], false).await;1248 run_with(&fx, &["build"], false).await;
@@ -1283,24 +1271,18 @@ async fn badge_label_is_trimmed_and_empty_means_absent() {
1283 blank.contains(">build</text>"),1271 blank.contains(">build</text>"),
1284 "blank label is absent: {blank}"1272 "blank label is absent: {blank}"
1285 );1273 );
1286-}1274+ let escaped = get(
1287-
1288-#[tokio::test]
1289-async fn badge_label_is_escaped() {
1290- let dir = tempfile::tempdir().expect("tempdir");
1291- let fx = fixture(dir.path()).await;
1292- run_with(&fx, &["build"], false).await;
1293- finish_job(&fx).await;
1294- let reader = Some(cookie_for("dave-token"));
1295- let svg = get(
1296 &fx.app,1275 &fx.app,
1297 "/tahinli/proj/badge.svg?label=%3Cb%3E%20a%20%26%20b%20%3E",1276 "/tahinli/proj/badge.svg?label=%3Cb%3E%20a%20%26%20b%20%3E",
1298 reader.as_deref(),1277 reader.as_deref(),
1299 )1278 )
1300 .await1279 .await
1301 .text();1280 .text();
1302- assert!(svg.contains("&lt;b&gt; a &amp; b &gt;"), "{svg}");1281+ assert!(escaped.contains("&lt;b&gt; a &amp; b &gt;"), "{escaped}");
1303- assert!(!svg.contains("<b>"), "raw markup must not reach the SVG");1282+ assert!(
1283+ !escaped.contains("<b>"),
1284+ "raw markup must not reach the SVG"
1285+ );
1304 }1286 }
1305 1287
1306 #[tokio::test]1288 #[tokio::test]
crates/forge-web/src/pages/commit.rsmodified+1 -13
@@ -299,6 +299,7 @@ mod tests {
299 assert!(text.contains("Body line one."));299 assert!(text.contains("Body line one."));
300 assert!(text.contains("class=\"mono\""));300 assert!(text.contains("class=\"mono\""));
301 assert!(text.contains("diff-file-body"));301 assert!(text.contains("diff-file-body"));
302+ assert!(!text.contains("sig-badge"), "unsigned commit has no badge");
302 }303 }
303 304
304 #[tokio::test]305 #[tokio::test]
@@ -389,19 +390,6 @@ mod tests {
389 assert_eq!(status, 404);390 assert_eq!(status, 404);
390 }391 }
391 392
392- #[tokio::test]
393- async fn unsigned_commit_page_has_no_signature_badge() {
394- let fx = Fixture::new(Visibility::Public).await;
395- let (status, _, body) = get(
396- &fx.router,
397- &format!("/{OWNER}/{REPO}/commit/{}", fx.modified),
398- )
399- .await;
400- assert_eq!(status, 200);
401- let html = String::from_utf8(body).unwrap();
402- assert!(!html.contains("sig-badge"));
403- }
404-
405 #[tokio::test]393 #[tokio::test]
406 async fn private_repo_is_404_for_anonymous() {394 async fn private_repo_is_404_for_anonymous() {
407 let fx = Fixture::new(Visibility::Private).await;395 let fx = Fixture::new(Visibility::Private).await;
crates/forge-web/src/pages/commits.rsmodified+4 -10
@@ -544,6 +544,10 @@ mod tests {
544 assert!(!html.contains("root commit"));544 assert!(!html.contains("root commit"));
545 assert!(html.contains(">Older<"));545 assert!(html.contains(">Older<"));
546 assert!(!html.contains(">Newer<"));546 assert!(!html.contains(">Newer<"));
547+ assert!(
548+ !html.contains("sig-badge"),
549+ "unsigned commits have no badge"
550+ );
547 551
548 let (status, _, body) = get(&fx.router, &format!("{base}?page=2")).await;552 let (status, _, body) = get(&fx.router, &format!("{base}?page=2")).await;
549 assert_eq!(status, 200);553 assert_eq!(status, 200);
@@ -672,16 +676,6 @@ mod tests {
672 assert!(html.contains("Body with 🎉 and 12:30:45"), "{html}");676 assert!(html.contains("Body with 🎉 and 12:30:45"), "{html}");
673 }677 }
674 678
675- #[tokio::test]
676- async fn unsigned_commits_have_no_signature_badge() {
677- let fx = Fixture::new(Visibility::Public).await;
678- let (status, _, body) = get(&fx.router, &format!("/{OWNER}/{REPO}/commits/main")).await;
679- assert_eq!(status, 200);
680- let html = String::from_utf8(body).unwrap();
681- assert!(html.contains("commit-row"));
682- assert!(!html.contains("sig-badge"));
683- }
684-
685 #[tokio::test]679 #[tokio::test]
686 async fn private_repo_is_404_for_anonymous() {680 async fn private_repo_is_404_for_anonymous() {
687 let fx = Fixture::new(Visibility::Private).await;681 let fx = Fixture::new(Visibility::Private).await;