Store tests share their store and merge into tables
Browse files at this commit7a15066c93d6e3f6632a9146dc339159838db412Parent: 965436c- test
- store tests share their store and merge into tables
13 changed files +555 -377
- crates/forge-core/src/store/admin_alerts.rs +11 -6
- crates/forge-core/src/store/advisories.rs +70 -55
- crates/forge-core/src/store/backup_runs.rs +27 -21
- crates/forge-core/src/store/lfs.rs +29 -17
- crates/forge-core/src/store/mirrors.rs +97 -71
- crates/forge-core/src/store/profile_pins.rs +72 -47
- crates/forge-core/src/store/push_recent.rs +8 -8
- crates/forge-core/src/store/releases.rs +90 -53
- crates/forge-core/src/store/replication.rs +46 -42
- crates/forge-core/src/store/repo_listing.rs +19 -21
- crates/forge-core/src/store/signatures.rs +47 -16
- crates/forge-core/src/store/snippets.rs +18 -1
- crates/forge-core/src/store/wiki.rs +21 -19
crates/forge-core/src/store/admin_alerts.rsmodified+11 -6
| @@ -311,9 +311,7 @@ mod tests { | ||
| 311 | 311 | (store, dir) |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - #[tokio::test] | |
| 315 | - async fn an_alert_is_raised_once_until_it_resolves() { | |
| 316 | - let (store, _dir) = store().await; | |
| 314 | + async fn an_alert_is_raised_once_until_it_resolves(store: &Store) { | |
| 317 | 315 | assert!( |
| 318 | 316 | store |
| 319 | 317 | .raise_alert("runner_offline:r1", "runner_offline", "ci-1", "") |
| @@ -352,9 +350,7 @@ mod tests { | ||
| 352 | 350 | ); |
| 353 | 351 | } |
| 354 | 352 | |
| 355 | - #[tokio::test] | |
| 356 | - async fn events_fire_once_and_are_never_active() { | |
| 357 | - let (store, _dir) = store().await; | |
| 353 | + async fn events_fire_once_and_are_never_active(store: &Store) { | |
| 358 | 354 | assert!( |
| 359 | 355 | store |
| 360 | 356 | .record_alert_event("ci_killed:run1", "ci_killed", "ci-1", "") |
| @@ -369,4 +365,13 @@ mod tests { | ||
| 369 | 365 | ); |
| 370 | 366 | assert!(store.active_alerts().await.unwrap().is_empty()); |
| 371 | 367 | } |
| 368 | + | |
| 369 | + // One store serves both. Events run first: they must not be active, and | |
| 370 | + // the raised alert below would otherwise show up in that empty check. | |
| 371 | + #[tokio::test] | |
| 372 | + async fn events_and_raised_alerts_share_one_store() { | |
| 373 | + let (store, _dir) = store().await; | |
| 374 | + events_fire_once_and_are_never_active(&store).await; | |
| 375 | + an_alert_is_raised_once_until_it_resolves(&store).await; | |
| 376 | + } | |
| 372 | 377 | } |
crates/forge-core/src/store/advisories.rsmodified+70 -55
| @@ -575,10 +575,14 @@ mod tests { | ||
| 575 | 575 | (store, repo.id) |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | + // Advisories are global, so each block replaces the advisory set it needs | |
| 579 | + // before scanning. The per-repo alert checks use their own repo. | |
| 578 | 580 | #[tokio::test] |
| 579 | - async fn scan_opens_reconciles_and_keeps_dismissed() { | |
| 581 | + async fn scans_reconcile_alerts_and_replace_per_ecosystem() { | |
| 580 | 582 | let dir = tempfile::tempdir().unwrap(); |
| 581 | 583 | let (store, repo) = store_with_repo(&dir).await; |
| 584 | + | |
| 585 | + // A scan opens alerts, closes fixed ones, and keeps dismissed ones. | |
| 582 | 586 | store |
| 583 | 587 | .replace_advisories( |
| 584 | 588 | "crates.io", |
| @@ -599,9 +603,14 @@ mod tests { | ||
| 599 | 603 | ScanOutcome { |
| 600 | 604 | opened: 2, |
| 601 | 605 | fixed: 0 |
| 602 | - } | |
| 606 | + }, | |
| 607 | + "first scan opens both" | |
| 608 | + ); | |
| 609 | + assert_eq!( | |
| 610 | + store.dependency_count(&repo).await.unwrap(), | |
| 611 | + 2, | |
| 612 | + "two dependencies" | |
| 603 | 613 | ); |
| 604 | - assert_eq!(store.dependency_count(&repo).await.unwrap(), 2); | |
| 605 | 614 | |
| 606 | 615 | // Upgrading `other` past its fix closes its alert. `old` stays vulnerable. |
| 607 | 616 | let second = store |
| @@ -613,7 +622,8 @@ mod tests { | ||
| 613 | 622 | ScanOutcome { |
| 614 | 623 | opened: 0, |
| 615 | 624 | fixed: 1 |
| 616 | - } | |
| 625 | + }, | |
| 626 | + "upgrade closes one" | |
| 617 | 627 | ); |
| 618 | 628 | let third = store |
| 619 | 629 | .scan_repo(&repo, &[dep("old", "1.0.0")]) |
| @@ -624,36 +634,39 @@ mod tests { | ||
| 624 | 634 | ScanOutcome { |
| 625 | 635 | opened: 0, |
| 626 | 636 | fixed: 0 |
| 627 | - } | |
| 637 | + }, | |
| 638 | + "nothing changes" | |
| 628 | 639 | ); |
| 629 | 640 | |
| 630 | 641 | let alerts = store.list_alerts(&repo).await.unwrap(); |
| 631 | - assert_eq!(alerts.len(), 2); | |
| 642 | + assert_eq!(alerts.len(), 2, "two alerts on the repo"); | |
| 632 | 643 | let open = alerts |
| 633 | 644 | .iter() |
| 634 | 645 | .find(|a| a.key.advisory_id == "RUSTSEC-1") |
| 635 | 646 | .unwrap(); |
| 636 | - assert_eq!(open.state, AlertState::Open); | |
| 637 | - assert_eq!(open.summary, "RUSTSEC-1 summary"); | |
| 638 | - assert_eq!(open.severity, "HIGH"); | |
| 647 | + assert_eq!(open.state, AlertState::Open, "open alert"); | |
| 648 | + assert_eq!(open.summary, "RUSTSEC-1 summary", "summary copied"); | |
| 649 | + assert_eq!(open.severity, "HIGH", "severity copied"); | |
| 639 | 650 | let fixed = alerts |
| 640 | 651 | .iter() |
| 641 | 652 | .find(|a| a.key.advisory_id == "RUSTSEC-2") |
| 642 | 653 | .unwrap(); |
| 643 | - assert_eq!(fixed.state, AlertState::Fixed); | |
| 654 | + assert_eq!(fixed.state, AlertState::Fixed, "fixed alert"); | |
| 644 | 655 | |
| 645 | 656 | // Dismiss, then a scan keeps it dismissed; a reopen moves it back. |
| 646 | 657 | assert!( |
| 647 | 658 | store |
| 648 | 659 | .set_alert_state(&repo, &open.key, AlertState::Open, AlertState::Dismissed) |
| 649 | 660 | .await |
| 650 | - .unwrap() | |
| 661 | + .unwrap(), | |
| 662 | + "dismiss applied" | |
| 651 | 663 | ); |
| 652 | 664 | assert!( |
| 653 | 665 | !store |
| 654 | 666 | .set_alert_state(&repo, &open.key, AlertState::Open, AlertState::Dismissed) |
| 655 | 667 | .await |
| 656 | - .unwrap() | |
| 668 | + .unwrap(), | |
| 669 | + "second dismiss is a no-op" | |
| 657 | 670 | ); |
| 658 | 671 | let kept = store |
| 659 | 672 | .scan_repo(&repo, &[dep("old", "1.0.0")]) |
| @@ -664,34 +677,38 @@ mod tests { | ||
| 664 | 677 | ScanOutcome { |
| 665 | 678 | opened: 0, |
| 666 | 679 | fixed: 0 |
| 667 | - } | |
| 680 | + }, | |
| 681 | + "dismissed alert stays put" | |
| 668 | 682 | ); |
| 669 | 683 | assert!( |
| 670 | 684 | store |
| 671 | 685 | .set_alert_state(&repo, &open.key, AlertState::Dismissed, AlertState::Open) |
| 672 | 686 | .await |
| 673 | - .unwrap() | |
| 687 | + .unwrap(), | |
| 688 | + "reopen applied" | |
| 674 | 689 | ); |
| 675 | - } | |
| 676 | 690 | |
| 677 | - #[tokio::test] | |
| 678 | - async fn fixed_alert_reopens_when_the_match_returns() { | |
| 679 | - let dir = tempfile::tempdir().unwrap(); | |
| 680 | - let (store, repo) = store_with_repo(&dir).await; | |
| 691 | + // A fixed alert reopens when the vulnerable match returns (own repo). | |
| 692 | + let owner = store.repo_by_id(&repo).await.unwrap().unwrap().owner_id; | |
| 693 | + let back = store | |
| 694 | + .create_repo(&owner, "back", "", crate::Visibility::Private, "main") | |
| 695 | + .await | |
| 696 | + .unwrap() | |
| 697 | + .id; | |
| 681 | 698 | store |
| 682 | 699 | .replace_advisories("crates.io", &[advisory("RUSTSEC-3", "back", "2.0.0")]) |
| 683 | 700 | .await |
| 684 | 701 | .unwrap(); |
| 685 | 702 | store |
| 686 | - .scan_repo(&repo, &[dep("back", "1.0.0")]) | |
| 703 | + .scan_repo(&back, &[dep("back", "1.0.0")]) | |
| 687 | 704 | .await |
| 688 | 705 | .unwrap(); |
| 689 | 706 | store |
| 690 | - .scan_repo(&repo, &[dep("back", "2.0.0")]) | |
| 707 | + .scan_repo(&back, &[dep("back", "2.0.0")]) | |
| 691 | 708 | .await |
| 692 | 709 | .unwrap(); |
| 693 | 710 | let again = store |
| 694 | - .scan_repo(&repo, &[dep("back", "1.0.1")]) | |
| 711 | + .scan_repo(&back, &[dep("back", "1.0.1")]) | |
| 695 | 712 | .await |
| 696 | 713 | .unwrap(); |
| 697 | 714 | assert_eq!( |
| @@ -699,11 +716,38 @@ mod tests { | ||
| 699 | 716 | ScanOutcome { |
| 700 | 717 | opened: 1, |
| 701 | 718 | fixed: 0 |
| 702 | - } | |
| 719 | + }, | |
| 720 | + "the match returns and reopens" | |
| 703 | 721 | ); |
| 704 | - let alerts = store.list_alerts(&repo).await.unwrap(); | |
| 705 | - assert_eq!(alerts.len(), 2); | |
| 706 | - assert_eq!(alerts[0].state, AlertState::Open); | |
| 722 | + let alerts = store.list_alerts(&back).await.unwrap(); | |
| 723 | + assert_eq!(alerts.len(), 2, "alert count on the back repo"); | |
| 724 | + assert_eq!(alerts[0].state, AlertState::Open, "reopened alert is open"); | |
| 725 | + | |
| 726 | + // Replacing advisories for one ecosystem leaves the others alone. | |
| 727 | + store | |
| 728 | + .replace_advisories("crates.io", &[advisory("RUSTSEC-4", "a", "2.0.0")]) | |
| 729 | + .await | |
| 730 | + .unwrap(); | |
| 731 | + store.replace_advisories("npm", &[]).await.unwrap(); | |
| 732 | + assert_eq!( | |
| 733 | + store | |
| 734 | + .advisories_for_package("crates.io", "a") | |
| 735 | + .await | |
| 736 | + .unwrap() | |
| 737 | + .len(), | |
| 738 | + 1, | |
| 739 | + "crates.io advisory kept" | |
| 740 | + ); | |
| 741 | + store | |
| 742 | + .replace_advisories("crates.io", &[advisory("RUSTSEC-5", "a", "3.0.0")]) | |
| 743 | + .await | |
| 744 | + .unwrap(); | |
| 745 | + let rows = store | |
| 746 | + .advisories_for_package("crates.io", "a") | |
| 747 | + .await | |
| 748 | + .unwrap(); | |
| 749 | + assert_eq!(rows.len(), 1, "replaced in place"); | |
| 750 | + assert_eq!(rows[0].id, "RUSTSEC-5", "the new advisory"); | |
| 707 | 751 | } |
| 708 | 752 | |
| 709 | 753 | #[tokio::test] |
| @@ -756,33 +800,4 @@ mod tests { | ||
| 756 | 800 | .unwrap(); |
| 757 | 801 | assert!(unread.is_empty()); |
| 758 | 802 | } |
| 759 | - | |
| 760 | - #[tokio::test] | |
| 761 | - async fn replacing_advisories_is_scoped_to_one_ecosystem() { | |
| 762 | - let dir = tempfile::tempdir().unwrap(); | |
| 763 | - let (store, _repo) = store_with_repo(&dir).await; | |
| 764 | - store | |
| 765 | - .replace_advisories("crates.io", &[advisory("RUSTSEC-4", "a", "2.0.0")]) | |
| 766 | - .await | |
| 767 | - .unwrap(); | |
| 768 | - store.replace_advisories("npm", &[]).await.unwrap(); | |
| 769 | - assert_eq!( | |
| 770 | - store | |
| 771 | - .advisories_for_package("crates.io", "a") | |
| 772 | - .await | |
| 773 | - .unwrap() | |
| 774 | - .len(), | |
| 775 | - 1 | |
| 776 | - ); | |
| 777 | - store | |
| 778 | - .replace_advisories("crates.io", &[advisory("RUSTSEC-5", "a", "3.0.0")]) | |
| 779 | - .await | |
| 780 | - .unwrap(); | |
| 781 | - let rows = store | |
| 782 | - .advisories_for_package("crates.io", "a") | |
| 783 | - .await | |
| 784 | - .unwrap(); | |
| 785 | - assert_eq!(rows.len(), 1); | |
| 786 | - assert_eq!(rows[0].id, "RUSTSEC-5"); | |
| 787 | - } | |
| 788 | 803 | } |
crates/forge-core/src/store/backup_runs.rsmodified+27 -21
| @@ -228,6 +228,33 @@ mod tests { | ||
| 228 | 228 | #[tokio::test] |
| 229 | 229 | async fn start_and_finish_round_trip() { |
| 230 | 230 | let (_dir, store) = store().await; |
| 231 | + | |
| 232 | + // The repo list starts empty and follows repo creation. | |
| 233 | + assert!( | |
| 234 | + store.repo_ids().await.expect("ids").is_empty(), | |
| 235 | + "no repos yet" | |
| 236 | + ); | |
| 237 | + let user = store | |
| 238 | + .create_user("tahinli", None, "hash", false) | |
| 239 | + .await | |
| 240 | + .expect("user"); | |
| 241 | + let repo = store | |
| 242 | + .create_repo( | |
| 243 | + &user.id, | |
| 244 | + "demo", | |
| 245 | + "", | |
| 246 | + crate::model::Visibility::Private, | |
| 247 | + "main", | |
| 248 | + ) | |
| 249 | + .await | |
| 250 | + .expect("repo"); | |
| 251 | + assert_eq!( | |
| 252 | + store.repo_ids().await.expect("ids"), | |
| 253 | + vec![repo.id], | |
| 254 | + "one repo listed" | |
| 255 | + ); | |
| 256 | + | |
| 257 | + // A run starts unfinished, then finishes with its outcome. | |
| 231 | 258 | let id = store |
| 232 | 259 | .start_run(RunKind::Backup, RunTrigger::Manual) |
| 233 | 260 | .await |
| @@ -325,25 +352,4 @@ mod tests { | ||
| 325 | 352 | assert_eq!(runs[1].id, ids[1]); |
| 326 | 353 | assert_eq!(store.recent_runs(0).await.expect("recent").len(), 1); |
| 327 | 354 | } |
| 328 | - | |
| 329 | - #[tokio::test] | |
| 330 | - async fn repo_ids_lists_every_repo() { | |
| 331 | - let (_dir, store) = store().await; | |
| 332 | - assert!(store.repo_ids().await.expect("ids").is_empty()); | |
| 333 | - let user = store | |
| 334 | - .create_user("tahinli", None, "hash", false) | |
| 335 | - .await | |
| 336 | - .expect("user"); | |
| 337 | - let repo = store | |
| 338 | - .create_repo( | |
| 339 | - &user.id, | |
| 340 | - "demo", | |
| 341 | - "", | |
| 342 | - crate::model::Visibility::Private, | |
| 343 | - "main", | |
| 344 | - ) | |
| 345 | - .await | |
| 346 | - .expect("repo"); | |
| 347 | - assert_eq!(store.repo_ids().await.expect("ids"), vec![repo.id]); | |
| 348 | - } | |
| 349 | 355 | } |
crates/forge-core/src/store/lfs.rsmodified+29 -17
| @@ -71,30 +71,42 @@ mod tests { | ||
| 71 | 71 | (store, repo.id, user.id) |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | + // One store serves both checks. Deleting a repo runs first, so the link | |
| 75 | + // check below starts from a store with no links at all. | |
| 74 | 76 | #[tokio::test] |
| 75 | - async fn links_are_per_repo_and_idempotent() { | |
| 77 | + async fn lfs_links_per_repo_idempotent_and_removed_with_repo() { | |
| 76 | 78 | let dir = tempfile::tempdir().unwrap(); |
| 77 | - let (store, repo_id, _) = repo_fixture(&dir).await; | |
| 78 | - assert_eq!(store.lfs_object_size(&repo_id, OID).await.unwrap(), None); | |
| 79 | - assert!(!store.lfs_oid_is_linked(OID).await.unwrap()); | |
| 79 | + let (store, repo_id, user_id) = repo_fixture(&dir).await; | |
| 80 | + | |
| 81 | + let gone = store | |
| 82 | + .create_repo(&user_id, "gone", "", Visibility::Public, "main") | |
| 83 | + .await | |
| 84 | + .unwrap() | |
| 85 | + .id; | |
| 86 | + store.insert_lfs_object(&gone, OID, 3).await.unwrap(); | |
| 87 | + store.delete_repo(&gone).await.unwrap(); | |
| 88 | + assert!( | |
| 89 | + !store.lfs_oid_is_linked(OID).await.unwrap(), | |
| 90 | + "delete_repo drops the link" | |
| 91 | + ); | |
| 92 | + | |
| 93 | + assert_eq!( | |
| 94 | + store.lfs_object_size(&repo_id, OID).await.unwrap(), | |
| 95 | + None, | |
| 96 | + "not linked yet" | |
| 97 | + ); | |
| 98 | + assert!( | |
| 99 | + !store.lfs_oid_is_linked(OID).await.unwrap(), | |
| 100 | + "no link anywhere" | |
| 101 | + ); | |
| 80 | 102 | |
| 81 | 103 | store.insert_lfs_object(&repo_id, OID, 12).await.unwrap(); |
| 82 | 104 | store.insert_lfs_object(&repo_id, OID, 12).await.unwrap(); |
| 83 | 105 | assert_eq!( |
| 84 | 106 | store.lfs_object_size(&repo_id, OID).await.unwrap(), |
| 85 | - Some(12) | |
| 107 | + Some(12), | |
| 108 | + "one link, size kept" | |
| 86 | 109 | ); |
| 87 | - assert!(store.lfs_oid_is_linked(OID).await.unwrap()); | |
| 88 | - } | |
| 89 | - | |
| 90 | - #[tokio::test] | |
| 91 | - async fn delete_repo_removes_lfs_rows() { | |
| 92 | - let dir = tempfile::tempdir().unwrap(); | |
| 93 | - let (store, repo_id, _) = repo_fixture(&dir).await; | |
| 94 | - store.insert_lfs_object(&repo_id, OID, 3).await.unwrap(); | |
| 95 | - | |
| 96 | - store.delete_repo(&repo_id).await.unwrap(); | |
| 97 | - | |
| 98 | - assert!(!store.lfs_oid_is_linked(OID).await.unwrap()); | |
| 110 | + assert!(store.lfs_oid_is_linked(OID).await.unwrap(), "linked"); | |
| 99 | 111 | } |
| 100 | 112 | } |
crates/forge-core/src/store/mirrors.rsmodified+97 -71
| @@ -424,9 +424,21 @@ mod tests { | ||
| 424 | 424 | ); |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | + async fn add_repo(store: &Store, owner: &User, name: &str) -> Repo { | |
| 428 | + store | |
| 429 | + .create_repo(&owner.id, name, "", Visibility::Public, "main") | |
| 430 | + .await | |
| 431 | + .unwrap() | |
| 432 | + } | |
| 433 | + | |
| 434 | + // Pull and push rules, interval checks, the result/delete path, repo | |
| 435 | + // deletion and the push-mirror cap share one store. Each block works on | |
| 436 | + // its own repo so the cases cannot interfere with each other. | |
| 427 | 437 | #[tokio::test] |
| 428 | - async fn one_pull_mirror_per_repo() { | |
| 429 | - let (store, _tahinli, repo, _dir) = setup().await; | |
| 438 | + async fn mirror_rules_and_lifecycle_per_repo() { | |
| 439 | + let (store, tahinli, repo, _dir) = setup().await; | |
| 440 | + | |
| 441 | + // One pull mirror per repo; push mirrors are not limited by that slot. | |
| 430 | 442 | let first = store |
| 431 | 443 | .create_mirror(&pull(&repo, "https://a.example/x.git")) |
| 432 | 444 | .await |
| @@ -435,34 +447,105 @@ mod tests { | ||
| 435 | 447 | assert!(first.enabled); |
| 436 | 448 | assert_eq!( |
| 437 | 449 | store.pull_mirror(&repo.id).await.unwrap().map(|m| m.id), |
| 438 | - Some(first.id.clone()) | |
| 450 | + Some(first.id.clone()), | |
| 451 | + "pull slot holds the first mirror" | |
| 439 | 452 | ); |
| 440 | 453 | let second = store |
| 441 | 454 | .create_mirror(&pull(&repo, "https://b.example/y.git")) |
| 442 | 455 | .await; |
| 443 | - assert!(matches!(second, Err(Error::Conflict(_))), "{second:?}"); | |
| 444 | - // Push mirrors are not limited by the pull slot. | |
| 456 | + assert!( | |
| 457 | + matches!(second, Err(Error::Conflict(_))), | |
| 458 | + "second pull: {second:?}" | |
| 459 | + ); | |
| 445 | 460 | store |
| 446 | 461 | .create_mirror(&push(&repo, "https://c.example/z.git")) |
| 447 | 462 | .await |
| 448 | 463 | .unwrap(); |
| 449 | - assert_eq!(store.list_mirrors(&repo.id).await.unwrap().len(), 2); | |
| 450 | - } | |
| 464 | + assert_eq!( | |
| 465 | + store.list_mirrors(&repo.id).await.unwrap().len(), | |
| 466 | + 2, | |
| 467 | + "one pull plus one push" | |
| 468 | + ); | |
| 451 | 469 | |
| 452 | - #[tokio::test] | |
| 453 | - async fn at_most_ten_push_mirrors() { | |
| 454 | - let (store, _tahinli, repo, _dir) = setup().await; | |
| 470 | + // Intervals: 5 minutes is too short, 0 means manual sync only. | |
| 471 | + let interval_repo = add_repo(&store, &tahinli, "interval").await; | |
| 472 | + let too_short = store | |
| 473 | + .create_mirror(&NewMirror { | |
| 474 | + interval_minutes: 5, | |
| 475 | + ..pull(&interval_repo, "https://a.example/x.git") | |
| 476 | + }) | |
| 477 | + .await; | |
| 478 | + assert!( | |
| 479 | + matches!(too_short, Err(Error::Invalid(_))), | |
| 480 | + "5 minutes: {too_short:?}" | |
| 481 | + ); | |
| 482 | + let manual = store | |
| 483 | + .create_mirror(&NewMirror { | |
| 484 | + interval_minutes: 0, | |
| 485 | + ..pull(&interval_repo, "https://a.example/x.git") | |
| 486 | + }) | |
| 487 | + .await | |
| 488 | + .unwrap(); | |
| 489 | + assert_eq!(manual.interval_minutes, 0, "manual interval kept"); | |
| 490 | + | |
| 491 | + // Recording a result, then deleting the mirror. | |
| 492 | + let record_repo = add_repo(&store, &tahinli, "record").await; | |
| 493 | + let m = store | |
| 494 | + .create_mirror(&pull(&record_repo, "https://a.example/x.git")) | |
| 495 | + .await | |
| 496 | + .unwrap(); | |
| 497 | + let next = stamp_after(Duration::from_secs(3600)); | |
| 498 | + store | |
| 499 | + .record_mirror_result(&m.id, false, Some("boom"), &next) | |
| 500 | + .await | |
| 501 | + .unwrap(); | |
| 502 | + let after = store.mirror(&m.id).await.unwrap().unwrap(); | |
| 503 | + assert_eq!(after.last_ok, Some(false), "result recorded"); | |
| 504 | + assert_eq!(after.last_error.as_deref(), Some("boom"), "error recorded"); | |
| 505 | + assert!(after.last_sync_at.is_some(), "sync time recorded"); | |
| 506 | + assert_eq!(after.next_sync_at, next, "next sync recorded"); | |
| 507 | + store.delete_mirror(&m.id).await.unwrap(); | |
| 508 | + assert!( | |
| 509 | + store.mirror(&m.id).await.unwrap().is_none(), | |
| 510 | + "mirror deleted" | |
| 511 | + ); | |
| 512 | + assert!( | |
| 513 | + matches!(store.delete_mirror(&m.id).await, Err(Error::NotFound)), | |
| 514 | + "deleting twice is NotFound" | |
| 515 | + ); | |
| 516 | + | |
| 517 | + // Deleting the repo removes its mirrors. | |
| 518 | + let gone = add_repo(&store, &tahinli, "gone").await; | |
| 519 | + let g = store | |
| 520 | + .create_mirror(&pull(&gone, "https://a.example/x.git")) | |
| 521 | + .await | |
| 522 | + .unwrap(); | |
| 523 | + store.delete_repo(&gone.id).await.unwrap(); | |
| 524 | + assert!( | |
| 525 | + store.mirror(&g.id).await.unwrap().is_none(), | |
| 526 | + "delete_repo removes mirrors" | |
| 527 | + ); | |
| 528 | + | |
| 529 | + // The push cap: ten per repo, the eleventh is refused. | |
| 530 | + let ten = add_repo(&store, &tahinli, "ten").await; | |
| 455 | 531 | for n in 0..MAX_PUSH_MIRRORS { |
| 456 | 532 | store |
| 457 | - .create_mirror(&push(&repo, &format!("https://h{n}.example/r.git"))) | |
| 533 | + .create_mirror(&push(&ten, &format!("https://h{n}.example/r.git"))) | |
| 458 | 534 | .await |
| 459 | 535 | .unwrap(); |
| 460 | 536 | } |
| 461 | 537 | let eleventh = store |
| 462 | - .create_mirror(&push(&repo, "https://h11.example/r.git")) | |
| 538 | + .create_mirror(&push(&ten, "https://h11.example/r.git")) | |
| 463 | 539 | .await; |
| 464 | - assert!(matches!(eleventh, Err(Error::Invalid(_))), "{eleventh:?}"); | |
| 465 | - assert_eq!(store.list_mirrors(&repo.id).await.unwrap().len(), 10); | |
| 540 | + assert!( | |
| 541 | + matches!(eleventh, Err(Error::Invalid(_))), | |
| 542 | + "eleventh push: {eleventh:?}" | |
| 543 | + ); | |
| 544 | + assert_eq!( | |
| 545 | + store.list_mirrors(&ten.id).await.unwrap().len(), | |
| 546 | + 10, | |
| 547 | + "cap holds" | |
| 548 | + ); | |
| 466 | 549 | } |
| 467 | 550 | |
| 468 | 551 | #[tokio::test] |
| @@ -631,61 +714,4 @@ mod tests { | ||
| 631 | 714 | store.schedule_mirror(&future.id, &now).await.unwrap(); |
| 632 | 715 | assert_eq!(store.due_mirrors(&now, 10).await.unwrap().len(), 3); |
| 633 | 716 | } |
| 634 | - | |
| 635 | - #[tokio::test] | |
| 636 | - async fn record_result_and_delete() { | |
| 637 | - let (store, _tahinli, repo, _dir) = setup().await; | |
| 638 | - let m = store | |
| 639 | - .create_mirror(&pull(&repo, "https://a.example/x.git")) | |
| 640 | - .await | |
| 641 | - .unwrap(); | |
| 642 | - let next = stamp_after(Duration::from_secs(3600)); | |
| 643 | - store | |
| 644 | - .record_mirror_result(&m.id, false, Some("boom"), &next) | |
| 645 | - .await | |
| 646 | - .unwrap(); | |
| 647 | - let after = store.mirror(&m.id).await.unwrap().unwrap(); | |
| 648 | - assert_eq!(after.last_ok, Some(false)); | |
| 649 | - assert_eq!(after.last_error.as_deref(), Some("boom")); | |
| 650 | - assert!(after.last_sync_at.is_some()); | |
| 651 | - assert_eq!(after.next_sync_at, next); | |
| 652 | - | |
| 653 | - store.delete_mirror(&m.id).await.unwrap(); | |
| 654 | - assert!(store.mirror(&m.id).await.unwrap().is_none()); | |
| 655 | - assert!(matches!( | |
| 656 | - store.delete_mirror(&m.id).await, | |
| 657 | - Err(Error::NotFound) | |
| 658 | - )); | |
| 659 | - } | |
| 660 | - | |
| 661 | - #[tokio::test] | |
| 662 | - async fn interval_is_validated() { | |
| 663 | - let (store, _tahinli, repo, _dir) = setup().await; | |
| 664 | - let too_short = store | |
| 665 | - .create_mirror(&NewMirror { | |
| 666 | - interval_minutes: 5, | |
| 667 | - ..pull(&repo, "https://a.example/x.git") | |
| 668 | - }) | |
| 669 | - .await; | |
| 670 | - assert!(matches!(too_short, Err(Error::Invalid(_)))); | |
| 671 | - let manual = store | |
| 672 | - .create_mirror(&NewMirror { | |
| 673 | - interval_minutes: 0, | |
| 674 | - ..pull(&repo, "https://a.example/x.git") | |
| 675 | - }) | |
| 676 | - .await | |
| 677 | - .unwrap(); | |
| 678 | - assert_eq!(manual.interval_minutes, 0); | |
| 679 | - } | |
| 680 | - | |
| 681 | - #[tokio::test] | |
| 682 | - async fn delete_repo_removes_mirrors() { | |
| 683 | - let (store, _tahinli, repo, _dir) = setup().await; | |
| 684 | - let m = store | |
| 685 | - .create_mirror(&pull(&repo, "https://a.example/x.git")) | |
| 686 | - .await | |
| 687 | - .unwrap(); | |
| 688 | - store.delete_repo(&repo.id).await.unwrap(); | |
| 689 | - assert!(store.mirror(&m.id).await.unwrap().is_none()); | |
| 690 | - } | |
| 691 | 717 | } |
crates/forge-core/src/store/profile_pins.rsmodified+72 -47
| @@ -146,68 +146,93 @@ mod tests { | ||
| 146 | 146 | .collect() |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | + // One store serves every scenario. Each scenario gets its own owner, so | |
| 150 | + // pin sets and the "repo-N" names never collide. | |
| 149 | 151 | #[tokio::test] |
| 150 | - async fn pins_keep_the_order_given_and_replace_the_old_set() { | |
| 151 | - let (store, tahinli, _, _dir) = fixture().await; | |
| 152 | + async fn profile_pin_rules() { | |
| 153 | + let (store, tahinli, foreign, _dir) = fixture().await; | |
| 154 | + | |
| 155 | + // Pins keep the order given and each save replaces the old set. | |
| 152 | 156 | let ids = make_repos(&store, &tahinli, 3).await; |
| 153 | 157 | store |
| 154 | 158 | .set_profile_pins(&tahinli, &[ids[2].clone(), ids[0].clone()]) |
| 155 | 159 | .await |
| 156 | 160 | .unwrap(); |
| 157 | - assert_eq!(pinned_names(&store, &tahinli).await, ["repo-2", "repo-0"]); | |
| 158 | - | |
| 161 | + assert_eq!( | |
| 162 | + pinned_names(&store, &tahinli).await, | |
| 163 | + ["repo-2", "repo-0"], | |
| 164 | + "order kept" | |
| 165 | + ); | |
| 159 | 166 | store |
| 160 | 167 | .set_profile_pins(&tahinli, &[ids[1].clone()]) |
| 161 | 168 | .await |
| 162 | 169 | .unwrap(); |
| 163 | - assert_eq!(pinned_names(&store, &tahinli).await, ["repo-1"]); | |
| 164 | - | |
| 170 | + assert_eq!( | |
| 171 | + pinned_names(&store, &tahinli).await, | |
| 172 | + ["repo-1"], | |
| 173 | + "old set replaced" | |
| 174 | + ); | |
| 165 | 175 | store.set_profile_pins(&tahinli, &[]).await.unwrap(); |
| 166 | - assert!(pinned_names(&store, &tahinli).await.is_empty()); | |
| 167 | - } | |
| 168 | - | |
| 169 | - #[tokio::test] | |
| 170 | - async fn more_than_six_pins_is_refused_and_keeps_the_old_pins() { | |
| 171 | - let (store, tahinli, _, _dir) = fixture().await; | |
| 172 | - let ids = make_repos(&store, &tahinli, 7).await; | |
| 173 | - store.set_profile_pins(&tahinli, &ids[..2]).await.unwrap(); | |
| 174 | - let too_many = store.set_profile_pins(&tahinli, &ids).await; | |
| 175 | - assert!(matches!(too_many, Err(Error::Invalid(_)))); | |
| 176 | - assert_eq!(pinned_names(&store, &tahinli).await, ["repo-0", "repo-1"]); | |
| 177 | - } | |
| 178 | - | |
| 179 | - #[tokio::test] | |
| 180 | - async fn foreign_and_repeated_repos_are_refused_atomically() { | |
| 181 | - let (store, tahinli, foreign, _dir) = fixture().await; | |
| 182 | - let ids = make_repos(&store, &tahinli, 1).await; | |
| 183 | - store.set_profile_pins(&tahinli, &ids[..1]).await.unwrap(); | |
| 184 | - | |
| 176 | + assert!( | |
| 177 | + pinned_names(&store, &tahinli).await.is_empty(), | |
| 178 | + "empty clears the pins" | |
| 179 | + ); | |
| 180 | + | |
| 181 | + // More than six pins is refused and the old pins stay. | |
| 182 | + let big = store.create_user("big", None, "h", false).await.unwrap(); | |
| 183 | + let ids = make_repos(&store, &big.id, 7).await; | |
| 184 | + store.set_profile_pins(&big.id, &ids[..2]).await.unwrap(); | |
| 185 | + let too_many = store.set_profile_pins(&big.id, &ids).await; | |
| 186 | + assert!( | |
| 187 | + matches!(too_many, Err(Error::Invalid(_))), | |
| 188 | + "seven pins: {too_many:?}" | |
| 189 | + ); | |
| 190 | + assert_eq!( | |
| 191 | + pinned_names(&store, &big.id).await, | |
| 192 | + ["repo-0", "repo-1"], | |
| 193 | + "old pins kept" | |
| 194 | + ); | |
| 195 | + | |
| 196 | + // Foreign and repeated repos are refused atomically. | |
| 197 | + let strict = store.create_user("strict", None, "h", false).await.unwrap(); | |
| 198 | + let ids = make_repos(&store, &strict.id, 1).await; | |
| 199 | + store.set_profile_pins(&strict.id, &ids[..1]).await.unwrap(); | |
| 185 | 200 | let stolen = store |
| 186 | - .set_profile_pins(&tahinli, &[ids[0].clone(), foreign]) | |
| 201 | + .set_profile_pins(&strict.id, &[ids[0].clone(), foreign.clone()]) | |
| 187 | 202 | .await; |
| 188 | - assert!(matches!(stolen, Err(Error::Invalid(_)))); | |
| 203 | + assert!( | |
| 204 | + matches!(stolen, Err(Error::Invalid(_))), | |
| 205 | + "foreign repo: {stolen:?}" | |
| 206 | + ); | |
| 189 | 207 | let repeated = store |
| 190 | - .set_profile_pins(&tahinli, &[ids[0].clone(), ids[0].clone()]) | |
| 208 | + .set_profile_pins(&strict.id, &[ids[0].clone(), ids[0].clone()]) | |
| 191 | 209 | .await; |
| 192 | - assert!(matches!(repeated, Err(Error::Invalid(_)))); | |
| 193 | - assert_eq!(pinned_names(&store, &tahinli).await, ["repo-0"]); | |
| 194 | - } | |
| 195 | - | |
| 196 | - #[tokio::test] | |
| 197 | - async fn deleting_a_pinned_repo_removes_its_pin() { | |
| 198 | - let (store, tahinli, _, _dir) = fixture().await; | |
| 199 | - let ids = make_repos(&store, &tahinli, 2).await; | |
| 200 | - store.set_profile_pins(&tahinli, &ids).await.unwrap(); | |
| 210 | + assert!( | |
| 211 | + matches!(repeated, Err(Error::Invalid(_))), | |
| 212 | + "repeated repo: {repeated:?}" | |
| 213 | + ); | |
| 214 | + assert_eq!( | |
| 215 | + pinned_names(&store, &strict.id).await, | |
| 216 | + ["repo-0"], | |
| 217 | + "nothing changed" | |
| 218 | + ); | |
| 219 | + | |
| 220 | + // Deleting a pinned repo removes its pin. | |
| 221 | + let gone = store.create_user("gone", None, "h", false).await.unwrap(); | |
| 222 | + let ids = make_repos(&store, &gone.id, 2).await; | |
| 223 | + store.set_profile_pins(&gone.id, &ids).await.unwrap(); | |
| 201 | 224 | store.delete_repo(&ids[0]).await.unwrap(); |
| 202 | - assert_eq!(pinned_names(&store, &tahinli).await, ["repo-1"]); | |
| 203 | - } | |
| 204 | - | |
| 205 | - #[tokio::test] | |
| 206 | - async fn owner_repos_by_activity_lists_every_owned_repo() { | |
| 207 | - let (store, tahinli, foreign, _dir) = fixture().await; | |
| 208 | - make_repos(&store, &tahinli, 2).await; | |
| 209 | - let listed = store.owner_repos_by_activity(&tahinli).await.unwrap(); | |
| 210 | - assert_eq!(listed.len(), 2); | |
| 211 | - assert!(listed.iter().all(|r| r.id != foreign)); | |
| 225 | + assert_eq!( | |
| 226 | + pinned_names(&store, &gone.id).await, | |
| 227 | + ["repo-1"], | |
| 228 | + "deleted pin removed" | |
| 229 | + ); | |
| 230 | + | |
| 231 | + // The activity list holds every owned repo and no foreign one. | |
| 232 | + let active = store.create_user("active", None, "h", false).await.unwrap(); | |
| 233 | + make_repos(&store, &active.id, 2).await; | |
| 234 | + let listed = store.owner_repos_by_activity(&active.id).await.unwrap(); | |
| 235 | + assert_eq!(listed.len(), 2, "both owned repos listed"); | |
| 236 | + assert!(listed.iter().all(|r| r.id != foreign), "no foreign repo"); | |
| 212 | 237 | } |
| 213 | 238 | } |
crates/forge-core/src/store/push_recent.rsmodified+8 -8
| @@ -116,8 +116,10 @@ mod tests { | ||
| 116 | 116 | (dir, store, tahinli.id, bob.id, demo.id, other.id) |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | + // One store serves both checks. The first one needs the store to hold only | |
| 120 | + // its own pushes, so the "now" push of the second one runs after it. | |
| 119 | 121 | #[tokio::test] |
| 120 | - async fn keeps_latest_per_branch_and_skips_deletions_and_others() { | |
| 122 | + async fn recent_branch_pushes_rules_and_empty_inputs() { | |
| 121 | 123 | let (_dir, store, tahinli, bob, demo, other) = store_with_repos().await; |
| 122 | 124 | let since = stamp_before(Duration::from_secs(3600)); |
| 123 | 125 | let older = stamp_before(Duration::from_secs(600)); |
| @@ -169,13 +171,11 @@ mod tests { | ||
| 169 | 171 | .unwrap(); |
| 170 | 172 | assert_eq!( |
| 171 | 173 | rows, |
| 172 | - vec![(demo.clone(), "feature".to_string(), newer.clone())] | |
| 174 | + vec![(demo.clone(), "feature".to_string(), newer.clone())], | |
| 175 | + "only the newest recent branch push" | |
| 173 | 176 | ); |
| 174 | - } | |
| 175 | 177 | |
| 176 | - #[tokio::test] | |
| 177 | - async fn empty_repo_list_and_future_since() { | |
| 178 | - let (_dir, store, tahinli, _bob, demo, _other) = store_with_repos().await; | |
| 178 | + // No repo ids, or a `since` in the future, gives nothing. | |
| 179 | 179 | store |
| 180 | 180 | .record_push_event(&demo, &tahinli, "refs/heads/feature", ZERO, OID, "test") |
| 181 | 181 | .await |
| @@ -184,12 +184,12 @@ mod tests { | ||
| 184 | 184 | .recent_branch_pushes(&[], &tahinli, &stamp_before(Duration::from_secs(3600))) |
| 185 | 185 | .await |
| 186 | 186 | .unwrap(); |
| 187 | - assert!(none.is_empty()); | |
| 187 | + assert!(none.is_empty(), "empty repo list"); | |
| 188 | 188 | let future = stamp_after(Duration::from_secs(3600)); |
| 189 | 189 | let none = store |
| 190 | 190 | .recent_branch_pushes(&[demo.as_str()], &tahinli, &future) |
| 191 | 191 | .await |
| 192 | 192 | .unwrap(); |
| 193 | - assert!(none.is_empty()); | |
| 193 | + assert!(none.is_empty(), "future since"); | |
| 194 | 194 | } |
| 195 | 195 | } |
crates/forge-core/src/store/releases.rsmodified+90 -53
| @@ -398,24 +398,44 @@ mod tests { | ||
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | + async fn add_repo(store: &Store, user: &str, name: &str) -> String { | |
| 402 | + store | |
| 403 | + .create_repo(user, name, "", crate::Visibility::Public, "main") | |
| 404 | + .await | |
| 405 | + .unwrap() | |
| 406 | + .id | |
| 407 | + } | |
| 408 | + | |
| 409 | + // Every scenario gets its own repo in one shared store, so the per-repo | |
| 410 | + // assertions cannot see another scenario's releases or assets. | |
| 401 | 411 | #[tokio::test] |
| 402 | - async fn drafts_are_unpublished_and_tags_are_unique_per_repo() { | |
| 403 | - let (_dir, store, user, repo) = store_with_repo().await; | |
| 412 | + async fn release_lifecycle_per_repo() { | |
| 413 | + let (_dir, store, user, _repo) = store_with_repo().await; | |
| 414 | + | |
| 415 | + // Drafts stay unpublished, and tags are unique per repo. | |
| 416 | + let repo = add_repo(&store, &user, "drafts").await; | |
| 404 | 417 | let draft = store |
| 405 | 418 | .create_release(&new_release(&repo, &user, "v1", true)) |
| 406 | 419 | .await |
| 407 | 420 | .unwrap(); |
| 408 | - assert!(draft.draft && draft.published_at.is_none()); | |
| 409 | - assert!(store.latest_release(&repo).await.unwrap().is_none()); | |
| 421 | + assert!( | |
| 422 | + draft.draft && draft.published_at.is_none(), | |
| 423 | + "draft is unpublished" | |
| 424 | + ); | |
| 425 | + assert!( | |
| 426 | + store.latest_release(&repo).await.unwrap().is_none(), | |
| 427 | + "no latest draft" | |
| 428 | + ); | |
| 410 | 429 | let again = store |
| 411 | 430 | .create_release(&new_release(&repo, &user, "v1", false)) |
| 412 | 431 | .await; |
| 413 | - assert!(matches!(again, Err(Error::Conflict(_)))); | |
| 414 | - } | |
| 432 | + assert!( | |
| 433 | + matches!(again, Err(Error::Conflict(_))), | |
| 434 | + "duplicate tag: {again:?}" | |
| 435 | + ); | |
| 415 | 436 | |
| 416 | - #[tokio::test] | |
| 417 | - async fn publishing_sets_published_at_once_and_latest_skips_prereleases() { | |
| 418 | - let (_dir, store, user, repo) = store_with_repo().await; | |
| 437 | + // Publishing sets published_at once; a prerelease is not "latest". | |
| 438 | + let repo = add_repo(&store, &user, "publish").await; | |
| 419 | 439 | let rel = store |
| 420 | 440 | .create_release(&new_release(&repo, &user, "v1", true)) |
| 421 | 441 | .await |
| @@ -426,10 +446,13 @@ mod tests { | ||
| 426 | 446 | draft: false, |
| 427 | 447 | prerelease: false, |
| 428 | 448 | }; |
| 429 | - assert!(store.update_release(&rel.id, &edit).await.unwrap()); | |
| 449 | + assert!( | |
| 450 | + store.update_release(&rel.id, &edit).await.unwrap(), | |
| 451 | + "publish applied" | |
| 452 | + ); | |
| 430 | 453 | let published = store.release(&rel.id).await.unwrap().unwrap(); |
| 431 | 454 | let stamp = published.published_at.clone(); |
| 432 | - assert!(stamp.is_some()); | |
| 455 | + assert!(stamp.is_some(), "publish stamps the release"); | |
| 433 | 456 | let edit = ReleaseEdit { |
| 434 | 457 | title: "v1b", |
| 435 | 458 | body: "", |
| @@ -439,7 +462,8 @@ mod tests { | ||
| 439 | 462 | store.update_release(&rel.id, &edit).await.unwrap(); |
| 440 | 463 | assert_eq!( |
| 441 | 464 | store.release(&rel.id).await.unwrap().unwrap().published_at, |
| 442 | - stamp | |
| 465 | + stamp, | |
| 466 | + "the stamp is set once" | |
| 443 | 467 | ); |
| 444 | 468 | let pre = store |
| 445 | 469 | .create_release(&NewRelease { |
| @@ -448,16 +472,15 @@ mod tests { | ||
| 448 | 472 | }) |
| 449 | 473 | .await |
| 450 | 474 | .unwrap(); |
| 451 | - assert!(pre.published_at.is_some()); | |
| 475 | + assert!(pre.published_at.is_some(), "prerelease is published"); | |
| 452 | 476 | assert_eq!( |
| 453 | 477 | store.latest_release(&repo).await.unwrap().unwrap().id, |
| 454 | - rel.id | |
| 478 | + rel.id, | |
| 479 | + "latest skips the prerelease" | |
| 455 | 480 | ); |
| 456 | - } | |
| 457 | 481 | |
| 458 | - #[tokio::test] | |
| 459 | - async fn assets_count_downloads_and_deleting_a_release_returns_its_blob_ids() { | |
| 460 | - let (_dir, store, user, repo) = store_with_repo().await; | |
| 482 | + // Downloads are counted; deleting a release returns its blob ids. | |
| 483 | + let repo = add_repo(&store, &user, "assets").await; | |
| 461 | 484 | let rel = store |
| 462 | 485 | .create_release(&new_release(&repo, &user, "v1", false)) |
| 463 | 486 | .await |
| @@ -474,7 +497,7 @@ mod tests { | ||
| 474 | 497 | }) |
| 475 | 498 | .await |
| 476 | 499 | .unwrap(); |
| 477 | - assert_eq!(asset.size, 3); | |
| 500 | + assert_eq!(asset.size, 3, "asset size"); | |
| 478 | 501 | store.count_asset_download("a1").await.unwrap(); |
| 479 | 502 | store.count_asset_download("a1").await.unwrap(); |
| 480 | 503 | let counted = store |
| @@ -482,27 +505,33 @@ mod tests { | ||
| 482 | 505 | .await |
| 483 | 506 | .unwrap() |
| 484 | 507 | .unwrap(); |
| 485 | - assert_eq!(counted.download_count, 2); | |
| 508 | + assert_eq!(counted.download_count, 2, "two downloads counted"); | |
| 486 | 509 | assert_eq!( |
| 487 | 510 | store.repo_release_asset_ids(&repo).await.unwrap(), |
| 488 | - vec!["a1".to_string()] | |
| 511 | + vec!["a1".to_string()], | |
| 512 | + "repo lists its asset" | |
| 489 | 513 | ); |
| 490 | 514 | let removed = store.delete_release(&rel.id).await.unwrap(); |
| 491 | - assert_eq!(removed, Some(vec!["a1".to_string()])); | |
| 492 | - assert!(store.release(&rel.id).await.unwrap().is_none()); | |
| 493 | - assert_eq!(store.delete_release(&rel.id).await.unwrap(), None); | |
| 494 | - } | |
| 515 | + assert_eq!(removed, Some(vec!["a1".to_string()]), "blob ids returned"); | |
| 516 | + assert!( | |
| 517 | + store.release(&rel.id).await.unwrap().is_none(), | |
| 518 | + "release deleted" | |
| 519 | + ); | |
| 520 | + assert_eq!( | |
| 521 | + store.delete_release(&rel.id).await.unwrap(), | |
| 522 | + None, | |
| 523 | + "second delete" | |
| 524 | + ); | |
| 495 | 525 | |
| 496 | - #[tokio::test] | |
| 497 | - async fn replacing_an_asset_swaps_its_file_and_keeps_name_and_count() { | |
| 498 | - let (_dir, store, user, repo) = store_with_repo().await; | |
| 526 | + // Replacing an asset swaps its file but keeps its name and counter. | |
| 527 | + let repo = add_repo(&store, &user, "replace").await; | |
| 499 | 528 | let rel = store |
| 500 | 529 | .create_release(&new_release(&repo, &user, "v1", false)) |
| 501 | 530 | .await |
| 502 | 531 | .unwrap(); |
| 503 | 532 | store |
| 504 | 533 | .add_asset(&NewAsset { |
| 505 | - id: "a1", | |
| 534 | + id: "b1", | |
| 506 | 535 | release_id: &rel.id, |
| 507 | 536 | name: "app.bin", |
| 508 | 537 | size: 3, |
| @@ -512,13 +541,12 @@ mod tests { | ||
| 512 | 541 | }) |
| 513 | 542 | .await |
| 514 | 543 | .unwrap(); |
| 515 | - store.count_asset_download("a1").await.unwrap(); | |
| 516 | - | |
| 544 | + store.count_asset_download("b1").await.unwrap(); | |
| 517 | 545 | let replaced = store |
| 518 | 546 | .replace_asset( |
| 519 | - "a1", | |
| 547 | + "b1", | |
| 520 | 548 | &NewAsset { |
| 521 | - id: "a2", | |
| 549 | + id: "b2", | |
| 522 | 550 | release_id: &rel.id, |
| 523 | 551 | name: "app.bin", |
| 524 | 552 | size: 5, |
| @@ -529,23 +557,26 @@ mod tests { | ||
| 529 | 557 | ) |
| 530 | 558 | .await |
| 531 | 559 | .unwrap(); |
| 532 | - assert_eq!(replaced.id, "a2"); | |
| 533 | - assert_eq!(replaced.name, "app.bin"); | |
| 534 | - assert_eq!(replaced.size, 5); | |
| 535 | - assert_eq!(replaced.sha256, "y"); | |
| 536 | - assert_eq!(replaced.content_type, "text/plain"); | |
| 560 | + assert_eq!(replaced.id, "b2", "new id"); | |
| 561 | + assert_eq!(replaced.name, "app.bin", "name kept"); | |
| 562 | + assert_eq!(replaced.size, 5, "new size"); | |
| 563 | + assert_eq!(replaced.sha256, "y", "new hash"); | |
| 564 | + assert_eq!(replaced.content_type, "text/plain", "new content type"); | |
| 537 | 565 | assert_eq!(replaced.download_count, 1, "the counter survives"); |
| 538 | - assert!(store.release_asset_by_id("a1").await.unwrap().is_none()); | |
| 566 | + assert!( | |
| 567 | + store.release_asset_by_id("b1").await.unwrap().is_none(), | |
| 568 | + "old id gone" | |
| 569 | + ); | |
| 539 | 570 | assert_eq!( |
| 540 | 571 | store.repo_release_asset_ids(&repo).await.unwrap(), |
| 541 | - vec!["a2".to_string()] | |
| 572 | + vec!["b2".to_string()], | |
| 573 | + "only the new asset remains" | |
| 542 | 574 | ); |
| 543 | - | |
| 544 | 575 | let gone = store |
| 545 | 576 | .replace_asset( |
| 546 | - "a1", | |
| 577 | + "b1", | |
| 547 | 578 | &NewAsset { |
| 548 | - id: "a3", | |
| 579 | + id: "b3", | |
| 549 | 580 | release_id: &rel.id, |
| 550 | 581 | name: "app.bin", |
| 551 | 582 | size: 1, |
| @@ -555,12 +586,13 @@ mod tests { | ||
| 555 | 586 | }, |
| 556 | 587 | ) |
| 557 | 588 | .await; |
| 558 | - assert!(matches!(gone, Err(Error::NotFound)), "{gone:?}"); | |
| 559 | - } | |
| 589 | + assert!( | |
| 590 | + matches!(gone, Err(Error::NotFound)), | |
| 591 | + "replacing a missing asset: {gone:?}" | |
| 592 | + ); | |
| 560 | 593 | |
| 561 | - #[tokio::test] | |
| 562 | - async fn retagging_moves_the_release_and_refuses_a_tag_another_release_uses() { | |
| 563 | - let (_dir, store, user, repo) = store_with_repo().await; | |
| 594 | + // Retagging moves the release, but not onto a tag another release uses. | |
| 595 | + let repo = add_repo(&store, &user, "retag").await; | |
| 564 | 596 | let first = store |
| 565 | 597 | .create_release(&new_release(&repo, &user, "v1", true)) |
| 566 | 598 | .await |
| @@ -574,18 +606,23 @@ mod tests { | ||
| 574 | 606 | store |
| 575 | 607 | .set_release_tag(&first.id, "v1b", new_target) |
| 576 | 608 | .await |
| 577 | - .unwrap() | |
| 609 | + .unwrap(), | |
| 610 | + "retag applied" | |
| 578 | 611 | ); |
| 579 | 612 | let moved = store.release(&first.id).await.unwrap().unwrap(); |
| 580 | - assert_eq!(moved.tag, "v1b"); | |
| 581 | - assert_eq!(moved.target_oid, new_target); | |
| 613 | + assert_eq!(moved.tag, "v1b", "tag moved"); | |
| 614 | + assert_eq!(moved.target_oid, new_target, "target moved"); | |
| 582 | 615 | let taken = store.set_release_tag(&first.id, "v2", new_target).await; |
| 583 | - assert!(matches!(taken, Err(Error::Conflict(_))), "{taken:?}"); | |
| 616 | + assert!( | |
| 617 | + matches!(taken, Err(Error::Conflict(_))), | |
| 618 | + "taken tag: {taken:?}" | |
| 619 | + ); | |
| 584 | 620 | assert!( |
| 585 | 621 | !store |
| 586 | 622 | .set_release_tag("missing", "v9", new_target) |
| 587 | 623 | .await |
| 588 | - .unwrap() | |
| 624 | + .unwrap(), | |
| 625 | + "unknown release is not retagged" | |
| 589 | 626 | ); |
| 590 | 627 | } |
| 591 | 628 |
crates/forge-core/src/store/replication.rsmodified+46 -42
| @@ -123,9 +123,43 @@ mod tests { | ||
| 123 | 123 | (dir, store) |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | + // One store serves both checks. The list check runs first, so its exact | |
| 127 | + // subject list is not affected by the "r1" row used further down. | |
| 126 | 128 | #[tokio::test] |
| 127 | - async fn ok_and_error_keep_the_other_fields() { | |
| 129 | + async fn status_list_delete_and_ok_or_error_keep_other_fields() { | |
| 128 | 130 | let (_dir, store) = store().await; |
| 131 | + | |
| 132 | + store.record_replication_ok("db", None).await.expect("db"); | |
| 133 | + store | |
| 134 | + .record_replication_error("b-repo", "x") | |
| 135 | + .await | |
| 136 | + .expect("b"); | |
| 137 | + store | |
| 138 | + .record_replication_error("a-repo", "y") | |
| 139 | + .await | |
| 140 | + .expect("a"); | |
| 141 | + let subjects: Vec<String> = store | |
| 142 | + .list_replication_status() | |
| 143 | + .await | |
| 144 | + .expect("list") | |
| 145 | + .into_iter() | |
| 146 | + .map(|s| s.subject) | |
| 147 | + .collect(); | |
| 148 | + assert_eq!(subjects, ["a-repo", "b-repo", "db"], "ordered by subject"); | |
| 149 | + | |
| 150 | + store | |
| 151 | + .delete_replication_status("a-repo") | |
| 152 | + .await | |
| 153 | + .expect("delete"); | |
| 154 | + assert!( | |
| 155 | + store | |
| 156 | + .replication_status("a-repo") | |
| 157 | + .await | |
| 158 | + .expect("get") | |
| 159 | + .is_none(), | |
| 160 | + "deleted row is gone" | |
| 161 | + ); | |
| 162 | + | |
| 129 | 163 | assert!(store.replication_status("r1").await.expect("get").is_none()); |
| 130 | 164 | |
| 131 | 165 | store |
| @@ -137,9 +171,9 @@ mod tests { | ||
| 137 | 171 | .await |
| 138 | 172 | .expect("get") |
| 139 | 173 | .expect("row"); |
| 140 | - assert!(first.last_ok_at.is_some()); | |
| 141 | - assert_eq!(first.refs_sha256.as_deref(), Some("abc")); | |
| 142 | - assert_eq!(first.last_error, None); | |
| 174 | + assert!(first.last_ok_at.is_some(), "success stamped"); | |
| 175 | + assert_eq!(first.refs_sha256.as_deref(), Some("abc"), "refs hash kept"); | |
| 176 | + assert_eq!(first.last_error, None, "no error yet"); | |
| 143 | 177 | |
| 144 | 178 | store |
| 145 | 179 | .record_replication_error("r1", "push failed") |
| @@ -150,12 +184,16 @@ mod tests { | ||
| 150 | 184 | .await |
| 151 | 185 | .expect("get") |
| 152 | 186 | .expect("row"); |
| 153 | - assert_eq!(failed.last_error.as_deref(), Some("push failed")); | |
| 187 | + assert_eq!( | |
| 188 | + failed.last_error.as_deref(), | |
| 189 | + Some("push failed"), | |
| 190 | + "error stored" | |
| 191 | + ); | |
| 154 | 192 | assert_eq!( |
| 155 | 193 | failed.last_ok_at, first.last_ok_at, |
| 156 | 194 | "a failure keeps the last success" |
| 157 | 195 | ); |
| 158 | - assert_eq!(failed.refs_sha256.as_deref(), Some("abc")); | |
| 196 | + assert_eq!(failed.refs_sha256.as_deref(), Some("abc"), "refs hash kept"); | |
| 159 | 197 | |
| 160 | 198 | store.record_replication_ok("r1", None).await.expect("ok"); |
| 161 | 199 | let healed = store |
| @@ -163,41 +201,7 @@ mod tests { | ||
| 163 | 201 | .await |
| 164 | 202 | .expect("get") |
| 165 | 203 | .expect("row"); |
| 166 | - assert_eq!(healed.last_error, None); | |
| 167 | - assert_eq!(healed.refs_sha256.as_deref(), Some("abc")); | |
| 168 | - } | |
| 169 | - | |
| 170 | - #[tokio::test] | |
| 171 | - async fn list_is_ordered_and_delete_removes_rows() { | |
| 172 | - let (_dir, store) = store().await; | |
| 173 | - store.record_replication_ok("db", None).await.expect("db"); | |
| 174 | - store | |
| 175 | - .record_replication_error("b-repo", "x") | |
| 176 | - .await | |
| 177 | - .expect("b"); | |
| 178 | - store | |
| 179 | - .record_replication_error("a-repo", "y") | |
| 180 | - .await | |
| 181 | - .expect("a"); | |
| 182 | - let subjects: Vec<String> = store | |
| 183 | - .list_replication_status() | |
| 184 | - .await | |
| 185 | - .expect("list") | |
| 186 | - .into_iter() | |
| 187 | - .map(|s| s.subject) | |
| 188 | - .collect(); | |
| 189 | - assert_eq!(subjects, ["a-repo", "b-repo", "db"]); | |
| 190 | - | |
| 191 | - store | |
| 192 | - .delete_replication_status("a-repo") | |
| 193 | - .await | |
| 194 | - .expect("delete"); | |
| 195 | - assert!( | |
| 196 | - store | |
| 197 | - .replication_status("a-repo") | |
| 198 | - .await | |
| 199 | - .expect("get") | |
| 200 | - .is_none() | |
| 201 | - ); | |
| 204 | + assert_eq!(healed.last_error, None, "success clears the error"); | |
| 205 | + assert_eq!(healed.refs_sha256.as_deref(), Some("abc"), "refs hash kept"); | |
| 202 | 206 | } |
| 203 | 207 | } |
crates/forge-core/src/store/repo_listing.rsmodified+19 -21
| @@ -237,9 +237,7 @@ mod tests { | ||
| 237 | 237 | .id |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - #[tokio::test] | |
| 241 | - async fn strangers_and_anonymous_viewers_never_see_private_repos() { | |
| 242 | - let fx = fixture().await; | |
| 240 | + async fn strangers_and_anonymous_viewers_never_see_private_repos(fx: &Fixture) { | |
| 243 | 241 | let stranger = fx |
| 244 | 242 | .store |
| 245 | 243 | .create_user("mira", None, "h", false) |
| @@ -254,9 +252,7 @@ mod tests { | ||
| 254 | 252 | ); |
| 255 | 253 | } |
| 256 | 254 | |
| 257 | - #[tokio::test] | |
| 258 | - async fn a_collaborator_sees_the_private_repo_they_work_on() { | |
| 259 | - let fx = fixture().await; | |
| 255 | + async fn a_collaborator_sees_the_private_repo_they_work_on(fx: &Fixture) { | |
| 260 | 256 | let carol = fx |
| 261 | 257 | .store |
| 262 | 258 | .create_user("carol", None, "h", false) |
| @@ -274,9 +270,7 @@ mod tests { | ||
| 274 | 270 | ); |
| 275 | 271 | } |
| 276 | 272 | |
| 277 | - #[tokio::test] | |
| 278 | - async fn an_admin_sees_everything() { | |
| 279 | - let fx = fixture().await; | |
| 273 | + async fn an_admin_sees_everything(fx: &Fixture) { | |
| 280 | 274 | let admin = fx.store.create_user("root", None, "h", true).await.unwrap(); |
| 281 | 275 | let scope = RepoScope::OwnedBy(&fx.owner.id); |
| 282 | 276 | assert_eq!( |
| @@ -308,13 +302,11 @@ mod tests { | ||
| 308 | 302 | } |
| 309 | 303 | } |
| 310 | 304 | |
| 311 | - #[tokio::test] | |
| 312 | - async fn org_roles_match_org_repo_role() { | |
| 313 | - let fx = fixture().await; | |
| 305 | + async fn org_roles_match_org_repo_role(fx: &Fixture) { | |
| 314 | 306 | let org = fx.store.create_org("acme", &fx.owner.id).await.unwrap(); |
| 315 | 307 | let member = fx |
| 316 | 308 | .store |
| 317 | - .create_user("mira", None, "h", false) | |
| 309 | + .create_user("ines", None, "h", false) | |
| 318 | 310 | .await |
| 319 | 311 | .unwrap(); |
| 320 | 312 | let outsider = fx.store.create_user("zed", None, "h", false).await.unwrap(); |
| @@ -369,14 +361,8 @@ mod tests { | ||
| 369 | 361 | check(&outsider, &[]).await; |
| 370 | 362 | } |
| 371 | 363 | |
| 372 | - #[tokio::test] | |
| 373 | - async fn stars_scope_filters_search_and_pages() { | |
| 374 | - let fx = fixture().await; | |
| 375 | - let fan = fx | |
| 376 | - .store | |
| 377 | - .create_user("mira", None, "h", false) | |
| 378 | - .await | |
| 379 | - .unwrap(); | |
| 364 | + async fn stars_scope_filters_search_and_pages(fx: &Fixture) { | |
| 365 | + let fan = fx.store.create_user("fan", None, "h", false).await.unwrap(); | |
| 380 | 366 | for name in ["open", "closed"] { |
| 381 | 367 | let id = repo_id(&fx.store, "tahinli", name).await; |
| 382 | 368 | fx.store.star(&fan.id, &id).await.unwrap(); |
| @@ -406,4 +392,16 @@ mod tests { | ||
| 406 | 392 | assert_eq!(rows.len(), 1); |
| 407 | 393 | assert_eq!(rows[0].0.name, "open"); |
| 408 | 394 | } |
| 395 | + | |
| 396 | + // The listing rules share one fixture; each check only adds what it needs, | |
| 397 | + // and the collaborator grant runs before the later checks. | |
| 398 | + #[tokio::test] | |
| 399 | + async fn repo_visibility_and_listing_rules() { | |
| 400 | + let fx = fixture().await; | |
| 401 | + strangers_and_anonymous_viewers_never_see_private_repos(&fx).await; | |
| 402 | + a_collaborator_sees_the_private_repo_they_work_on(&fx).await; | |
| 403 | + an_admin_sees_everything(&fx).await; | |
| 404 | + org_roles_match_org_repo_role(&fx).await; | |
| 405 | + stars_scope_filters_search_and_pages(&fx).await; | |
| 406 | + } | |
| 409 | 407 | } |
crates/forge-core/src/store/signatures.rsmodified+47 -16
| @@ -323,37 +323,48 @@ mod tests { | ||
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | #[tokio::test] |
| 326 | - async fn gpg_key_round_trip_and_duplicate_fingerprint() { | |
| 326 | + async fn gpg_keys_add_list_and_delete_only_for_owner() { | |
| 327 | 327 | let (store, tahinli, _, _dir) = setup().await; |
| 328 | 328 | let emails = vec!["tahinli@example.com".to_string()]; |
| 329 | 329 | let key = store |
| 330 | 330 | .add_gpg_key(&tahinli, "ABCD", "-----BEGIN-----", &emails) |
| 331 | 331 | .await |
| 332 | 332 | .unwrap(); |
| 333 | - assert_eq!(key.emails, emails); | |
| 333 | + assert_eq!(key.emails, emails, "emails kept"); | |
| 334 | 334 | let listed = store.list_gpg_keys(&tahinli).await.unwrap(); |
| 335 | - assert_eq!(listed, vec![key.clone()]); | |
| 336 | - assert_eq!(store.all_gpg_keys().await.unwrap().len(), 1); | |
| 335 | + assert_eq!(listed, vec![key.clone()], "listed once"); | |
| 336 | + assert_eq!( | |
| 337 | + store.all_gpg_keys().await.unwrap().len(), | |
| 338 | + 1, | |
| 339 | + "one key overall" | |
| 340 | + ); | |
| 337 | 341 | let dup = store.add_gpg_key(&tahinli, "ABCD", "x", &emails).await; |
| 338 | - assert!(matches!(dup, Err(Error::Conflict(_)))); | |
| 339 | - } | |
| 342 | + assert!( | |
| 343 | + matches!(dup, Err(Error::Conflict(_))), | |
| 344 | + "duplicate fingerprint: {dup:?}" | |
| 345 | + ); | |
| 340 | 346 | |
| 341 | - #[tokio::test] | |
| 342 | - async fn delete_gpg_key_only_for_owner() { | |
| 343 | - let (store, tahinli, _, _dir) = setup().await; | |
| 347 | + // Another user cannot delete the key; the owner can. | |
| 344 | 348 | let bob = store.create_user("bob", None, "hash", false).await.unwrap(); |
| 345 | - let key = store.add_gpg_key(&tahinli, "ABCD", "x", &[]).await.unwrap(); | |
| 346 | 349 | assert!( |
| 347 | 350 | store |
| 348 | 351 | .delete_gpg_key(&bob.id, &key.id) |
| 349 | 352 | .await |
| 350 | 353 | .unwrap() |
| 351 | - .is_none() | |
| 354 | + .is_none(), | |
| 355 | + "not the owner" | |
| 356 | + ); | |
| 357 | + assert_eq!( | |
| 358 | + store.list_gpg_keys(&tahinli).await.unwrap().len(), | |
| 359 | + 1, | |
| 360 | + "still there" | |
| 352 | 361 | ); |
| 353 | - assert_eq!(store.list_gpg_keys(&tahinli).await.unwrap().len(), 1); | |
| 354 | 362 | let removed = store.delete_gpg_key(&tahinli, &key.id).await.unwrap(); |
| 355 | - assert_eq!(removed, Some(key)); | |
| 356 | - assert!(store.list_gpg_keys(&tahinli).await.unwrap().is_empty()); | |
| 363 | + assert_eq!(removed, Some(key), "owner removes it"); | |
| 364 | + assert!( | |
| 365 | + store.list_gpg_keys(&tahinli).await.unwrap().is_empty(), | |
| 366 | + "list empty" | |
| 367 | + ); | |
| 357 | 368 | } |
| 358 | 369 | |
| 359 | 370 | #[tokio::test] |
| @@ -411,11 +422,31 @@ mod tests { | ||
| 411 | 422 | SigStatus::UnknownKey, |
| 412 | 423 | SigStatus::Bad, |
| 413 | 424 | ] { |
| 414 | - assert_eq!(s.as_str().parse::<SigStatus>().unwrap(), s); | |
| 425 | + assert_eq!( | |
| 426 | + s.as_str().parse::<SigStatus>().unwrap(), | |
| 427 | + s, | |
| 428 | + "round trip {s:?}" | |
| 429 | + ); | |
| 415 | 430 | } |
| 416 | 431 | for k in [SigKind::Ssh, SigKind::Gpg] { |
| 417 | - assert_eq!(k.as_str().parse::<SigKind>().unwrap(), k); | |
| 432 | + assert_eq!( | |
| 433 | + k.as_str().parse::<SigKind>().unwrap(), | |
| 434 | + k, | |
| 435 | + "round trip {k:?}" | |
| 436 | + ); | |
| 437 | + } | |
| 438 | + // Stored in the signature cache, so the literals must not change. | |
| 439 | + for (s, literal) in [ | |
| 440 | + (SigStatus::Verified, "verified"), | |
| 441 | + (SigStatus::Unverified, "unverified"), | |
| 442 | + (SigStatus::Unsigned, "unsigned"), | |
| 443 | + (SigStatus::UnknownKey, "unknown_key"), | |
| 444 | + (SigStatus::Bad, "bad"), | |
| 445 | + ] { | |
| 446 | + assert_eq!(s.as_str(), literal, "stored literal of {s:?}"); | |
| 418 | 447 | } |
| 448 | + assert_eq!(SigKind::Ssh.as_str(), "ssh", "stored literal of ssh"); | |
| 449 | + assert_eq!(SigKind::Gpg.as_str(), "gpg", "stored literal of gpg"); | |
| 419 | 450 | assert!("nope".parse::<SigStatus>().is_err()); |
| 420 | 451 | } |
| 421 | 452 | } |
crates/forge-core/src/store/snippets.rsmodified+18 -1
| @@ -492,7 +492,24 @@ mod tests { | ||
| 492 | 492 | #[test] |
| 493 | 493 | fn visibility_names_round_trip() { |
| 494 | 494 | for v in SnippetVisibility::ALL { |
| 495 | - assert_eq!(SnippetVisibility::parse(v.as_str()), Some(v)); | |
| 495 | + assert_eq!( | |
| 496 | + SnippetVisibility::parse(v.as_str()), | |
| 497 | + Some(v), | |
| 498 | + "round trip {v:?}" | |
| 499 | + ); | |
| 500 | + } | |
| 501 | + // The stored literals: changing one breaks saved snippets. | |
| 502 | + for (v, literal) in [ | |
| 503 | + (SnippetVisibility::Public, "public"), | |
| 504 | + (SnippetVisibility::Unlisted, "unlisted"), | |
| 505 | + (SnippetVisibility::Private, "private"), | |
| 506 | + ] { | |
| 507 | + assert_eq!(v.as_str(), literal, "stored literal of {v:?}"); | |
| 508 | + assert_eq!( | |
| 509 | + SnippetVisibility::parse(literal), | |
| 510 | + Some(v), | |
| 511 | + "parse {literal}" | |
| 512 | + ); | |
| 496 | 513 | } |
| 497 | 514 | assert_eq!(SnippetVisibility::parse("secret"), None); |
| 498 | 515 | } |
crates/forge-core/src/store/wiki.rsmodified+21 -19
| @@ -44,7 +44,7 @@ mod tests { | ||
| 44 | 44 | use crate::model::Visibility; |
| 45 | 45 | |
| 46 | 46 | #[tokio::test] |
| 47 | - async fn wiki_is_on_by_default_and_can_be_switched() { | |
| 47 | + async fn wiki_is_on_by_default_can_be_switched_and_unknown_repo_is_not_found() { | |
| 48 | 48 | let dir = tempfile::tempdir().unwrap(); |
| 49 | 49 | let store = Store::open(&dir.path().join("forge.db")).await.unwrap(); |
| 50 | 50 | let tahinli = store |
| @@ -55,26 +55,28 @@ mod tests { | ||
| 55 | 55 | .create_repo(&tahinli.id, "proj", "", Visibility::Public, "main") |
| 56 | 56 | .await |
| 57 | 57 | .unwrap(); |
| 58 | - assert!(store.wiki_enabled(&repo.id).await.unwrap()); | |
| 58 | + assert!(store.wiki_enabled(&repo.id).await.unwrap(), "on by default"); | |
| 59 | 59 | store.set_wiki_enabled(&repo.id, false).await.unwrap(); |
| 60 | - assert!(!store.wiki_enabled(&repo.id).await.unwrap()); | |
| 60 | + assert!(!store.wiki_enabled(&repo.id).await.unwrap(), "switched off"); | |
| 61 | 61 | store.set_wiki_enabled(&repo.id, true).await.unwrap(); |
| 62 | - assert!(store.wiki_enabled(&repo.id).await.unwrap()); | |
| 63 | - } | |
| 62 | + assert!(store.wiki_enabled(&repo.id).await.unwrap(), "switched on"); | |
| 64 | 63 | |
| 65 | - #[tokio::test] | |
| 66 | - async fn unknown_repo_is_not_found() { | |
| 67 | - let dir = tempfile::tempdir().unwrap(); | |
| 68 | - let store = Store::open(&dir.path().join("forge.db")).await.unwrap(); | |
| 69 | - assert!(matches!( | |
| 70 | - store.wiki_enabled("01ARZ3NDEKTSV4RRFFQ69G5FAV").await, | |
| 71 | - Err(Error::NotFound) | |
| 72 | - )); | |
| 73 | - assert!(matches!( | |
| 74 | - store | |
| 75 | - .set_wiki_enabled("01ARZ3NDEKTSV4RRFFQ69G5FAV", false) | |
| 76 | - .await, | |
| 77 | - Err(Error::NotFound) | |
| 78 | - )); | |
| 64 | + // An id that is no repo is not found, for read and for write. | |
| 65 | + assert!( | |
| 66 | + matches!( | |
| 67 | + store.wiki_enabled("01ARZ3NDEKTSV4RRFFQ69G5FAV").await, | |
| 68 | + Err(Error::NotFound) | |
| 69 | + ), | |
| 70 | + "unknown repo read" | |
| 71 | + ); | |
| 72 | + assert!( | |
| 73 | + matches!( | |
| 74 | + store | |
| 75 | + .set_wiki_enabled("01ARZ3NDEKTSV4RRFFQ69G5FAV", false) | |
| 76 | + .await, | |
| 77 | + Err(Error::NotFound) | |
| 78 | + ), | |
| 79 | + "unknown repo write" | |
| 80 | + ); | |
| 79 | 81 | } |
| 80 | 82 | } |