diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 13:05:15 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 13:05:15 +0000 |
| commit | e11ddc792864f9f0f84887701d919b6c8dc32fe0 (patch) | |
| tree | 6c2ae0cd5dc3aa8da8c88eb7f80d481b93bcfe0f | |
| parent | 70dd57966969f24fb81aabe412fb3667486f87b5 (diff) | |
test(pull): local commits on uptodate proposal
add test for scenario
| -rw-r--r-- | tests/pull.rs | 136 |
1 files changed, 131 insertions, 5 deletions
diff --git a/tests/pull.rs b/tests/pull.rs index 39f3ef4..ac43dc8 100644 --- a/tests/pull.rs +++ b/tests/pull.rs | |||
| @@ -439,11 +439,137 @@ mod when_branch_is_checked_out { | |||
| 439 | } | 439 | } |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | mod when_branch_is_ahead { | 442 | mod when_local_commits_on_uptodate_proposal { |
| 443 | // use super::*; | 443 | use super::*; |
| 444 | // TODO latest commit in proposal builds off an older commit in proposal | 444 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { |
| 445 | // instead of previous. | 445 | // fallback (51,52) user write (53, 55) repo (55, 56) |
| 446 | // TODO current git user created commit on branch | 446 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( |
| 447 | Relay::new(8051, None, None), | ||
| 448 | Relay::new(8052, None, None), | ||
| 449 | Relay::new(8053, None, None), | ||
| 450 | Relay::new(8055, None, None), | ||
| 451 | Relay::new(8056, None, None), | ||
| 452 | ); | ||
| 453 | |||
| 454 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 455 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 456 | r51.events.push(generate_repo_ref_event()); | ||
| 457 | |||
| 458 | r55.events.push(generate_repo_ref_event()); | ||
| 459 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 460 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 461 | |||
| 462 | let cli_tester_handle = std::thread::spawn( | ||
| 463 | move || -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 464 | let originating_repo = cli_tester_create_proposals()?; | ||
| 465 | |||
| 466 | let test_repo = GitTestRepo::default(); | ||
| 467 | test_repo.populate()?; | ||
| 468 | |||
| 469 | create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; | ||
| 470 | // add appended commit to local branch | ||
| 471 | std::fs::write(test_repo.dir.join("appended.md"), "some content")?; | ||
| 472 | test_repo.stage_and_commit("appended commit")?; | ||
| 473 | |||
| 474 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 475 | p.expect("finding proposal root event...\r\n")?; | ||
| 476 | p.expect("found proposal root event. finding commits...\r\n")?; | ||
| 477 | p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?; | ||
| 478 | p.expect_end()?; | ||
| 479 | |||
| 480 | for p in [51, 52, 53, 55, 56] { | ||
| 481 | relay::shutdown_relay(8000 + p)?; | ||
| 482 | } | ||
| 483 | Ok((originating_repo, test_repo)) | ||
| 484 | }, | ||
| 485 | ); | ||
| 486 | |||
| 487 | // launch relay | ||
| 488 | let _ = join!( | ||
| 489 | r51.listen_until_close(), | ||
| 490 | r52.listen_until_close(), | ||
| 491 | r53.listen_until_close(), | ||
| 492 | r55.listen_until_close(), | ||
| 493 | r56.listen_until_close(), | ||
| 494 | ); | ||
| 495 | let res = cli_tester_handle.join().unwrap()?; | ||
| 496 | |||
| 497 | Ok(res) | ||
| 498 | } | ||
| 499 | |||
| 500 | mod cli_prompts { | ||
| 501 | use super::*; | ||
| 502 | async fn run_async_prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 503 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 504 | Relay::new(8051, None, None), | ||
| 505 | Relay::new(8052, None, None), | ||
| 506 | Relay::new(8053, None, None), | ||
| 507 | Relay::new(8055, None, None), | ||
| 508 | Relay::new(8056, None, None), | ||
| 509 | ); | ||
| 510 | |||
| 511 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 512 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 513 | r51.events.push(generate_repo_ref_event()); | ||
| 514 | |||
| 515 | r55.events.push(generate_repo_ref_event()); | ||
| 516 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 517 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 518 | |||
| 519 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 520 | cli_tester_create_proposals()?; | ||
| 521 | |||
| 522 | let test_repo = GitTestRepo::default(); | ||
| 523 | test_repo.populate()?; | ||
| 524 | |||
| 525 | create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; | ||
| 526 | // add appended commit to local branch | ||
| 527 | std::fs::write(test_repo.dir.join("appended.md"), "some content")?; | ||
| 528 | test_repo.stage_and_commit("appended commit")?; | ||
| 529 | |||
| 530 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 531 | p.expect("finding proposal root event...\r\n")?; | ||
| 532 | p.expect("found proposal root event. finding commits...\r\n")?; | ||
| 533 | p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?; | ||
| 534 | p.expect_end()?; | ||
| 535 | |||
| 536 | for p in [51, 52, 53, 55, 56] { | ||
| 537 | relay::shutdown_relay(8000 + p)?; | ||
| 538 | } | ||
| 539 | Ok(()) | ||
| 540 | }); | ||
| 541 | |||
| 542 | // launch relay | ||
| 543 | let _ = join!( | ||
| 544 | r51.listen_until_close(), | ||
| 545 | r52.listen_until_close(), | ||
| 546 | r53.listen_until_close(), | ||
| 547 | r55.listen_until_close(), | ||
| 548 | r56.listen_until_close(), | ||
| 549 | ); | ||
| 550 | cli_tester_handle.join().unwrap()?; | ||
| 551 | println!("{:?}", r55.events); | ||
| 552 | Ok(()) | ||
| 553 | } | ||
| 554 | |||
| 555 | #[tokio::test] | ||
| 556 | #[serial] | ||
| 557 | async fn prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 558 | let _ = run_async_prompts_to_choose_from_proposal_titles().await; | ||
| 559 | Ok(()) | ||
| 560 | } | ||
| 561 | } | ||
| 562 | |||
| 563 | #[tokio::test] | ||
| 564 | #[serial] | ||
| 565 | async fn didnt_overwrite_local_appendments() -> Result<()> { | ||
| 566 | let (originating_repo, test_repo) = prep_and_run().await?; | ||
| 567 | assert_ne!( | ||
| 568 | test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 569 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 570 | ); | ||
| 571 | Ok(()) | ||
| 572 | } | ||
| 447 | } | 573 | } |
| 448 | 574 | ||
| 449 | mod when_latest_event_rebases_branch { | 575 | mod when_latest_event_rebases_branch { |