Merged tests drop needless borrows and name their complex types
Browse files at this commit5852a685c1c8a567f1940e21d10d046f2de1e63dParent: b757c23- lint
- merged tests drop needless borrows and name their complex types
7 changed files +35 -30
- crates/forge-web/src/api/statuses.rs +2 -1
- crates/forge-web/src/git_auth.rs +2 -1
- crates/forge-web/src/pages/browse_tests.rs +13 -13
- crates/forge-web/src/pages/forgot.rs +12 -12
- crates/forge-web/src/pages/new_repo.rs +2 -1
- crates/forge-web/src/signatures.rs +2 -1
- crates/forge-web/src/views/heatmap.rs +2 -1
crates/forge-web/src/api/statuses.rsmodified+2 -1
| @@ -361,7 +361,8 @@ mod tests { | |||
| 361 | let bad_sha = report_uri("abc123"); | 361 | let bad_sha = report_uri("abc123"); |
| 362 | let missing = report_uri(&"0".repeat(40)); | 362 | let missing = report_uri(&"0".repeat(40)); |
| 363 | // (case, uri, auth, cookie, body, expected status, expects a JSON error body) | 363 | // (case, uri, auth, cookie, body, expected status, expects a JSON error body) |
| 364 | - let cases: [(&str, &str, Option<&str>, Option<&str>, Option<&str>, u16, bool); 10] = [ | 364 | + type Case<'a> = (&'a str, &'a str, Option<&'a str>, Option<&'a str>, Option<&'a str>, u16, bool); |
| 365 | + let cases: [Case<'_>; 10] = [ | ||
| 365 | ("read-only token", report.as_str(), Some(reader.as_str()), None, Some(SUCCESS), 403, true), | 366 | ("read-only token", report.as_str(), Some(reader.as_str()), None, Some(SUCCESS), 403, true), |
| 366 | ("anonymous", report.as_str(), None, None, Some(SUCCESS), 401, true), | 367 | ("anonymous", report.as_str(), None, None, Some(SUCCESS), 401, true), |
| 367 | ("bad token", report.as_str(), Some("Bearer forge_not_a_real_token"), None, Some(SUCCESS), 401, false), | 368 | ("bad token", report.as_str(), Some("Bearer forge_not_a_real_token"), None, Some(SUCCESS), 401, false), |
crates/forge-web/src/git_auth.rsmodified+2 -1
| @@ -102,7 +102,8 @@ mod tests { | |||
| 102 | fn parse_basic_auth_cases() { | 102 | fn parse_basic_auth_cases() { |
| 103 | // One labelled table: each case keeps its own input and expected result. | 103 | // One labelled table: each case keeps its own input and expected result. |
| 104 | let t = BASE64_STANDARD.encode("tahinli:t"); | 104 | let t = BASE64_STANDARD.encode("tahinli:t"); |
| 105 | - let cases: Vec<(&str, String, Option<(&str, &str)>)> = vec![ | 105 | + type Case<'a> = (&'a str, String, Option<(&'a str, &'a str)>); |
| 106 | + let cases: Vec<Case<'_>> = vec![ | ||
| 106 | ( | 107 | ( |
| 107 | "user and token", | 108 | "user and token", |
| 108 | basic("tahinli:forge_abc"), | 109 | basic("tahinli:forge_abc"), |
crates/forge-web/src/pages/browse_tests.rsmodified+13 -13
| @@ -73,7 +73,7 @@ fn whitespace_commit(fx: &Fixture) -> String { | |||
| 73 | 73 | ||
| 74 | /// The commit toolbar, and the whitespace toggle that hides whitespace-only files. | 74 | /// The commit toolbar, and the whitespace toggle that hides whitespace-only files. |
| 75 | async fn scenario_whitespace_toolbar(fx: &Fixture) { | 75 | async fn scenario_whitespace_toolbar(fx: &Fixture) { |
| 76 | - let oid = whitespace_commit(&fx); | 76 | + let oid = whitespace_commit(fx); |
| 77 | let base = format!("/{OWNER}/{REPO}/commit/{oid}"); | 77 | let base = format!("/{OWNER}/{REPO}/commit/{oid}"); |
| 78 | 78 | ||
| 79 | let (status, _, body) = get(&fx.router, &base).await; | 79 | let (status, _, body) = get(&fx.router, &base).await; |
| @@ -275,7 +275,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | |||
| 275 | ); | 275 | ); |
| 276 | let page = format!("/{OWNER}/{REPO}/branches"); | 276 | let page = format!("/{OWNER}/{REPO}/branches"); |
| 277 | 277 | ||
| 278 | - let (status, _, html) = send(&fx.router, "GET", &page, Some(&cookie), &[]).await; | 278 | + let (status, _, html) = send(&fx.router, "GET", &page, Some(cookie), &[]).await; |
| 279 | assert_eq!(status, 200); | 279 | assert_eq!(status, 200); |
| 280 | // feature is 1 ahead of and 54 behind main (the root is its base, main has 54 more commits). | 280 | // feature is 1 ahead of and 54 behind main (the root is its base, main has 54 more commits). |
| 281 | assert!(html.contains("1 ahead, 54 behind"), "{html}"); | 281 | assert!(html.contains("1 ahead, 54 behind"), "{html}"); |
| @@ -292,7 +292,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | |||
| 292 | &fx.router, | 292 | &fx.router, |
| 293 | "POST", | 293 | "POST", |
| 294 | &page, | 294 | &page, |
| 295 | - Some(&cookie), | 295 | + Some(cookie), |
| 296 | &[("csrf", CSRF), ("name", "topic/one"), ("from", "feature")], | 296 | &[("csrf", CSRF), ("name", "topic/one"), ("from", "feature")], |
| 297 | ) | 297 | ) |
| 298 | .await; | 298 | .await; |
| @@ -314,7 +314,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | |||
| 314 | &fx.router, | 314 | &fx.router, |
| 315 | "POST", | 315 | "POST", |
| 316 | &page, | 316 | &page, |
| 317 | - Some(&cookie), | 317 | + Some(cookie), |
| 318 | &[("csrf", CSRF), ("name", name), ("from", from)], | 318 | &[("csrf", CSRF), ("name", name), ("from", from)], |
| 319 | ) | 319 | ) |
| 320 | .await; | 320 | .await; |
| @@ -338,7 +338,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | |||
| 338 | &fx.router, | 338 | &fx.router, |
| 339 | "POST", | 339 | "POST", |
| 340 | &page, | 340 | &page, |
| 341 | - Some(&cookie), | 341 | + Some(cookie), |
| 342 | &[("csrf", "wrong"), ("name", "x"), ("from", "main")], | 342 | &[("csrf", "wrong"), ("name", "x"), ("from", "main")], |
| 343 | ) | 343 | ) |
| 344 | .await; | 344 | .await; |
| @@ -350,7 +350,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | |||
| 350 | &fx.router, | 350 | &fx.router, |
| 351 | "POST", | 351 | "POST", |
| 352 | &delete, | 352 | &delete, |
| 353 | - Some(&cookie), | 353 | + Some(cookie), |
| 354 | &[("csrf", CSRF), ("name", "topic/one"), ("oid", &fx.root)], | 354 | &[("csrf", CSRF), ("name", "topic/one"), ("oid", &fx.root)], |
| 355 | ) | 355 | ) |
| 356 | .await; | 356 | .await; |
| @@ -360,7 +360,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | |||
| 360 | &fx.router, | 360 | &fx.router, |
| 361 | "POST", | 361 | "POST", |
| 362 | &delete, | 362 | &delete, |
| 363 | - Some(&cookie), | 363 | + Some(cookie), |
| 364 | &[("csrf", CSRF), ("name", "topic/one"), ("oid", &feature_tip)], | 364 | &[("csrf", CSRF), ("name", "topic/one"), ("oid", &feature_tip)], |
| 365 | ) | 365 | ) |
| 366 | .await; | 366 | .await; |
| @@ -374,7 +374,7 @@ async fn scenario_branches(fx: &Fixture, cookie: &str) { | |||
| 374 | &fx.router, | 374 | &fx.router, |
| 375 | "POST", | 375 | "POST", |
| 376 | &delete, | 376 | &delete, |
| 377 | - Some(&cookie), | 377 | + Some(cookie), |
| 378 | &[("csrf", CSRF), ("name", "main"), ("oid", &main_tip)], | 378 | &[("csrf", CSRF), ("name", "main"), ("oid", &main_tip)], |
| 379 | ) | 379 | ) |
| 380 | .await; | 380 | .await; |
| @@ -402,7 +402,7 @@ async fn scenario_protection(fx: &Fixture, cookie: &str) { | |||
| 402 | &fx.router, | 402 | &fx.router, |
| 403 | "POST", | 403 | "POST", |
| 404 | &delete, | 404 | &delete, |
| 405 | - Some(&cookie), | 405 | + Some(cookie), |
| 406 | &[("csrf", CSRF), ("name", "release/1"), ("oid", &tip)], | 406 | &[("csrf", CSRF), ("name", "release/1"), ("oid", &tip)], |
| 407 | ) | 407 | ) |
| 408 | .await; | 408 | .await; |
| @@ -412,7 +412,7 @@ async fn scenario_protection(fx: &Fixture, cookie: &str) { | |||
| 412 | &fx.router, | 412 | &fx.router, |
| 413 | "POST", | 413 | "POST", |
| 414 | &delete, | 414 | &delete, |
| 415 | - Some(&cookie), | 415 | + Some(cookie), |
| 416 | &[("csrf", CSRF), ("name", "scratch"), ("oid", &tip)], | 416 | &[("csrf", CSRF), ("name", "scratch"), ("oid", &tip)], |
| 417 | ) | 417 | ) |
| 418 | .await; | 418 | .await; |
| @@ -428,7 +428,7 @@ async fn scenario_default_branch(fx: &Fixture, cookie: &str) { | |||
| 428 | &fx.router, | 428 | &fx.router, |
| 429 | "POST", | 429 | "POST", |
| 430 | &settings, | 430 | &settings, |
| 431 | - Some(&cookie), | 431 | + Some(cookie), |
| 432 | &[ | 432 | &[ |
| 433 | ("csrf", CSRF), | 433 | ("csrf", CSRF), |
| 434 | ("description", "demo"), | 434 | ("description", "demo"), |
| @@ -452,7 +452,7 @@ async fn scenario_default_branch(fx: &Fixture, cookie: &str) { | |||
| 452 | &fx.router, | 452 | &fx.router, |
| 453 | "POST", | 453 | "POST", |
| 454 | &settings, | 454 | &settings, |
| 455 | - Some(&cookie), | 455 | + Some(cookie), |
| 456 | &[ | 456 | &[ |
| 457 | ("csrf", CSRF), | 457 | ("csrf", CSRF), |
| 458 | ("description", "demo"), | 458 | ("description", "demo"), |
| @@ -474,7 +474,7 @@ async fn scenario_default_branch(fx: &Fixture, cookie: &str) { | |||
| 474 | &fx.router, | 474 | &fx.router, |
| 475 | "GET", | 475 | "GET", |
| 476 | &format!("/{OWNER}/{REPO}/settings"), | 476 | &format!("/{OWNER}/{REPO}/settings"), |
| 477 | - Some(&cookie), | 477 | + Some(cookie), |
| 478 | &[], | 478 | &[], |
| 479 | ) | 479 | ) |
| 480 | .await; | 480 | .await; |
crates/forge-web/src/pages/forgot.rsmodified+12 -12
| @@ -291,10 +291,10 @@ mod tests { | |||
| 291 | .await | 291 | .await |
| 292 | .unwrap(); | 292 | .unwrap(); |
| 293 | for address in ["nobody@example.com", "frank@example.com"] { | 293 | for address in ["nobody@example.com", "frank@example.com"] { |
| 294 | - let (cookie, precsrf) = precsrf_for(&router, "/forgot").await; | 294 | + let (cookie, precsrf) = precsrf_for(router, "/forgot").await; |
| 295 | let form = format!("precsrf={precsrf}&email={}", address.replace('@', "%40")); | 295 | let form = format!("precsrf={precsrf}&email={}", address.replace('@', "%40")); |
| 296 | let (status, _, html) = | 296 | let (status, _, html) = |
| 297 | - send(&router, "POST", "/forgot", Some(&cookie), Some(&form)).await; | 297 | + send(router, "POST", "/forgot", Some(&cookie), Some(&form)).await; |
| 298 | assert_eq!(status, 200, "{address}"); | 298 | assert_eq!(status, 200, "{address}"); |
| 299 | assert!(html.contains("a reset link is on its way"), "{address}"); | 299 | assert!(html.contains("a reset link is on its way"), "{address}"); |
| 300 | } | 300 | } |
| @@ -326,21 +326,21 @@ mod tests { | |||
| 326 | .is_some() | 326 | .is_some() |
| 327 | ); | 327 | ); |
| 328 | 328 | ||
| 329 | - let (cookie, precsrf) = precsrf_for(&router, "/forgot").await; | 329 | + let (cookie, precsrf) = precsrf_for(router, "/forgot").await; |
| 330 | let form = format!("precsrf={precsrf}&email=gina%40example.com"); | 330 | let form = format!("precsrf={precsrf}&email=gina%40example.com"); |
| 331 | - let (status, _, _) = send(&router, "POST", "/forgot", Some(&cookie), Some(&form)).await; | 331 | + let (status, _, _) = send(router, "POST", "/forgot", Some(&cookie), Some(&form)).await; |
| 332 | assert_eq!(status, 200); | 332 | assert_eq!(status, 200); |
| 333 | - let body = wait_for_mail(&state, "/reset/").await; | 333 | + let body = wait_for_mail(state, "/reset/").await; |
| 334 | let path = link_in(&body, "/reset/"); | 334 | let path = link_in(&body, "/reset/"); |
| 335 | 335 | ||
| 336 | - let (status, _, html) = send(&router, "GET", &path, None, None).await; | 336 | + let (status, _, html) = send(router, "GET", &path, None, None).await; |
| 337 | assert_eq!(status, 200); | 337 | assert_eq!(status, 200); |
| 338 | assert!(html.contains("Set a new password")); | 338 | assert!(html.contains("Set a new password")); |
| 339 | 339 | ||
| 340 | - let (cookie, precsrf) = precsrf_for(&router, &path).await; | 340 | + let (cookie, precsrf) = precsrf_for(router, &path).await; |
| 341 | let form = | 341 | let form = |
| 342 | format!("precsrf={precsrf}&password=brand-new-password-1&confirm=brand-new-password-1"); | 342 | format!("precsrf={precsrf}&password=brand-new-password-1&confirm=brand-new-password-1"); |
| 343 | - let (status, _, html) = send(&router, "POST", &path, Some(&cookie), Some(&form)).await; | 343 | + let (status, _, html) = send(router, "POST", &path, Some(&cookie), Some(&form)).await; |
| 344 | assert_eq!(status, 200); | 344 | assert_eq!(status, 200); |
| 345 | assert!(html.contains("Your password is changed")); | 345 | assert!(html.contains("Your password is changed")); |
| 346 | 346 | ||
| @@ -352,10 +352,10 @@ mod tests { | |||
| 352 | ); | 352 | ); |
| 353 | 353 | ||
| 354 | // The same link is spent now. | 354 | // The same link is spent now. |
| 355 | - let (cookie, precsrf) = precsrf_for(&router, &path).await; | 355 | + let (cookie, precsrf) = precsrf_for(router, &path).await; |
| 356 | let form = | 356 | let form = |
| 357 | format!("precsrf={precsrf}&password=another-password-22&confirm=another-password-22"); | 357 | format!("precsrf={precsrf}&password=another-password-22&confirm=another-password-22"); |
| 358 | - let (status, _, html) = send(&router, "POST", &path, Some(&cookie), Some(&form)).await; | 358 | + let (status, _, html) = send(router, "POST", &path, Some(&cookie), Some(&form)).await; |
| 359 | assert_eq!(status, 200); | 359 | assert_eq!(status, 200); |
| 360 | assert!(html.contains("This reset link is invalid")); | 360 | assert!(html.contains("This reset link is invalid")); |
| 361 | } | 361 | } |
| @@ -376,9 +376,9 @@ mod tests { | |||
| 376 | let token = state.store.create_reset_token(&user.id).await.unwrap(); | 376 | let token = state.store.create_reset_token(&user.id).await.unwrap(); |
| 377 | let path = format!("/reset/{token}"); | 377 | let path = format!("/reset/{token}"); |
| 378 | 378 | ||
| 379 | - let (cookie, precsrf) = precsrf_for(&router, &path).await; | 379 | + let (cookie, precsrf) = precsrf_for(router, &path).await; |
| 380 | let form = format!("precsrf={precsrf}&password=short&confirm=short"); | 380 | let form = format!("precsrf={precsrf}&password=short&confirm=short"); |
| 381 | - let (status, _, html) = send(&router, "POST", &path, Some(&cookie), Some(&form)).await; | 381 | + let (status, _, html) = send(router, "POST", &path, Some(&cookie), Some(&form)).await; |
| 382 | assert_eq!(status, 200); | 382 | assert_eq!(status, 200); |
| 383 | assert!( | 383 | assert!( |
| 384 | html.contains("Set a new password"), | 384 | html.contains("Set a new password"), |
crates/forge-web/src/pages/new_repo.rsmodified+2 -1
| @@ -498,7 +498,8 @@ mod tests { | |||
| 498 | #[tokio::test] | 498 | #[tokio::test] |
| 499 | async fn default_labels_are_added_only_when_checked() { | 499 | async fn default_labels_are_added_only_when_checked() { |
| 500 | let site = site().await; | 500 | let site = site().await; |
| 501 | - let cases: [(&str, &[(&str, &str)], usize); 2] = [ | 501 | + type Case<'a> = (&'a str, &'a [(&'a str, &'a str)], usize); |
| 502 | + let cases: [Case<'_>; 2] = [ | ||
| 502 | ("checked", &[("default_labels", "on")], 9), | 503 | ("checked", &[("default_labels", "on")], 9), |
| 503 | ("unchecked", &[], 0), | 504 | ("unchecked", &[], 0), |
| 504 | ]; | 505 | ]; |
crates/forge-web/src/signatures.rsmodified+2 -1
| @@ -793,7 +793,8 @@ mod tests { | |||
| 793 | #[test] | 793 | #[test] |
| 794 | fn key_listing_parses_one_key_or_rejects() { | 794 | fn key_listing_parses_one_key_or_rejects() { |
| 795 | // (name, colon listing, expected Some((primary fingerprint, emails)) or None for rejection) | 795 | // (name, colon listing, expected Some((primary fingerprint, emails)) or None for rejection) |
| 796 | - let cases: Vec<(&str, &str, Option<(&str, Vec<&str>)>)> = vec![ | 796 | + type Case<'a> = (&'a str, &'a str, Option<(&'a str, Vec<&'a str>)>); |
| 797 | + let cases: Vec<Case<'_>> = vec![ | ||
| 797 | ( | 798 | ( |
| 798 | "primary fingerprint and emails", | 799 | "primary fingerprint and emails", |
| 799 | "pub:u:255:22:ABCDEF0123456789ABCDEF0123456789ABCDEF01:1700000000::::::23::0:\n\ | 800 | "pub:u:255:22:ABCDEF0123456789ABCDEF0123456789ABCDEF01:1700000000::::::23::0:\n\ |
crates/forge-web/src/views/heatmap.rsmodified+2 -1
| @@ -354,7 +354,8 @@ mod tests { | |||
| 354 | #[test] | 354 | #[test] |
| 355 | fn a_gap_or_an_old_run_ends_the_current_streak() { | 355 | fn a_gap_or_an_old_run_ends_the_current_streak() { |
| 356 | // (case, counts, current streak, longest streak) | 356 | // (case, counts, current streak, longest streak) |
| 357 | - let cases: [(&str, &[(&str, u32)], u64, u64); 2] = [ | 357 | + type Case<'a> = (&'a str, &'a [(&'a str, u32)], u64, u64); |
| 358 | + let cases: [Case<'_>; 2] = [ | ||
| 358 | ( | 359 | ( |
| 359 | "old run", | 360 | "old run", |
| 360 | &[("2026-10-01", 3), ("2026-10-02", 3)], | 361 | &[("2026-10-01", 3), ("2026-10-02", 3)], |