diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-06 10:12:26 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-06 10:59:24 +0100 |
| commit | f1aa1be738af0dc80eb3b5827249bb537de1e0cd (patch) | |
| tree | 4974673e04f6b05484450bbad44c545ca73bd27b /tests/git_remote_helper.rs | |
| parent | 5ee6a65d7f095d5ba2d40e47bd97b2e65ed2443f (diff) | |
feat(remote): `list` includes open proposals
and filters out other branches in `prs/*` namespace
Diffstat (limited to 'tests/git_remote_helper.rs')
| -rw-r--r-- | tests/git_remote_helper.rs | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/git_remote_helper.rs b/tests/git_remote_helper.rs index 4a60e63..77d7ecb 100644 --- a/tests/git_remote_helper.rs +++ b/tests/git_remote_helper.rs | |||
| @@ -447,6 +447,106 @@ mod list { | |||
| 447 | Ok(()) | 447 | Ok(()) |
| 448 | } | 448 | } |
| 449 | } | 449 | } |
| 450 | |||
| 451 | mod when_there_are_open_proposals { | ||
| 452 | |||
| 453 | use super::*; | ||
| 454 | |||
| 455 | #[tokio::test] | ||
| 456 | #[serial] | ||
| 457 | async fn open_proposal_listed_in_prs_namespace() -> Result<()> { | ||
| 458 | let (state_event, source_git_repo) = generate_repo_with_state_event().await?; | ||
| 459 | let source_path = source_git_repo.dir.to_str().unwrap().to_string(); | ||
| 460 | |||
| 461 | let main_commit_id = source_git_repo.get_tip_of_local_branch("main")?; | ||
| 462 | let example_commit_id = | ||
| 463 | source_git_repo.get_tip_of_local_branch("example-branch")?; | ||
| 464 | |||
| 465 | let git_repo = prep_git_repo()?; | ||
| 466 | |||
| 467 | let events = vec![ | ||
| 468 | generate_test_key_1_metadata_event("fred"), | ||
| 469 | generate_test_key_1_relay_list_event(), | ||
| 470 | generate_repo_ref_event_with_git_server(vec![ | ||
| 471 | source_git_repo.dir.to_str().unwrap().to_string(), | ||
| 472 | ]), | ||
| 473 | state_event, | ||
| 474 | ]; | ||
| 475 | // fallback (51,52) user write (53, 55) repo (55, 56) blaster (57) | ||
| 476 | let (mut r51, mut r52, mut r53, mut r55, mut r56, mut r57) = ( | ||
| 477 | Relay::new(8051, None, None), | ||
| 478 | Relay::new(8052, None, None), | ||
| 479 | Relay::new(8053, None, None), | ||
| 480 | Relay::new(8055, None, None), | ||
| 481 | Relay::new(8056, None, None), | ||
| 482 | Relay::new(8057, None, None), | ||
| 483 | ); | ||
| 484 | r51.events = events.clone(); | ||
| 485 | r55.events = events; | ||
| 486 | |||
| 487 | let cli_tester_handle = std::thread::spawn(move || -> Result<String> { | ||
| 488 | cli_tester_create_proposals()?; | ||
| 489 | |||
| 490 | let mut p = cli_tester_after_fetch(&git_repo)?; | ||
| 491 | p.send_line("list")?; | ||
| 492 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | ||
| 493 | // println!("{}", p.expect_eventually("\r\n\r\n")?); | ||
| 494 | let res = p.expect_eventually("\r\n\r\n")?; | ||
| 495 | |||
| 496 | p.exit()?; | ||
| 497 | for p in [51, 52, 53, 55, 56, 57] { | ||
| 498 | relay::shutdown_relay(8000 + p)?; | ||
| 499 | } | ||
| 500 | Ok(res) | ||
| 501 | }); | ||
| 502 | // launch relays | ||
| 503 | let _ = join!( | ||
| 504 | r51.listen_until_close(), | ||
| 505 | r52.listen_until_close(), | ||
| 506 | r53.listen_until_close(), | ||
| 507 | r55.listen_until_close(), | ||
| 508 | r56.listen_until_close(), | ||
| 509 | r57.listen_until_close(), | ||
| 510 | ); | ||
| 511 | |||
| 512 | let res = cli_tester_handle.join().unwrap()?; | ||
| 513 | |||
| 514 | let proposal_creation_repo = cli_tester_create_proposal_branches_ready_to_send()?; | ||
| 515 | |||
| 516 | let mut pr_refs = vec![]; | ||
| 517 | for name in [ | ||
| 518 | FEATURE_BRANCH_NAME_1, | ||
| 519 | FEATURE_BRANCH_NAME_2, | ||
| 520 | FEATURE_BRANCH_NAME_3, | ||
| 521 | ] { | ||
| 522 | pr_refs.push(format!( | ||
| 523 | "{} {}", | ||
| 524 | proposal_creation_repo.get_tip_of_local_branch(name)?, | ||
| 525 | get_proposal_branch_name_from_events(&r55.events, name)?, | ||
| 526 | )); | ||
| 527 | } | ||
| 528 | |||
| 529 | assert_eq!( | ||
| 530 | res.split("\r\n") | ||
| 531 | .map(|e| e.to_string()) | ||
| 532 | .collect::<HashSet<String>>(), | ||
| 533 | [ | ||
| 534 | vec![ | ||
| 535 | "@refs/heads/main HEAD".to_string(), | ||
| 536 | format!("{} refs/heads/main", main_commit_id), | ||
| 537 | format!("{} refs/heads/example-branch", example_commit_id), | ||
| 538 | ], | ||
| 539 | pr_refs, | ||
| 540 | ] | ||
| 541 | .concat() | ||
| 542 | .iter() | ||
| 543 | .cloned() | ||
| 544 | .collect::<HashSet<String>>() | ||
| 545 | ); | ||
| 546 | |||
| 547 | Ok(()) | ||
| 548 | } | ||
| 549 | } | ||
| 450 | } | 550 | } |
| 451 | } | 551 | } |
| 452 | 552 | ||