diff options
Diffstat (limited to 'tests/pull.rs')
| -rw-r--r-- | tests/pull.rs | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/tests/pull.rs b/tests/pull.rs index ac43dc8..102d9e2 100644 --- a/tests/pull.rs +++ b/tests/pull.rs | |||
| @@ -439,6 +439,166 @@ mod when_branch_is_checked_out { | |||
| 439 | } | 439 | } |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | mod when_old_proposal_revision_ammended_locally { | ||
| 443 | use super::*; | ||
| 444 | |||
| 445 | mod cli_prompts { | ||
| 446 | use super::*; | ||
| 447 | async fn run_async_prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 448 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 449 | Relay::new(8051, None, None), | ||
| 450 | Relay::new(8052, None, None), | ||
| 451 | Relay::new(8053, None, None), | ||
| 452 | Relay::new(8055, None, None), | ||
| 453 | Relay::new(8056, None, None), | ||
| 454 | ); | ||
| 455 | |||
| 456 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 457 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 458 | r51.events.push(generate_repo_ref_event()); | ||
| 459 | |||
| 460 | r55.events.push(generate_repo_ref_event()); | ||
| 461 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 462 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 463 | |||
| 464 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 465 | cli_tester_create_proposals()?; | ||
| 466 | |||
| 467 | let test_repo = GitTestRepo::default(); | ||
| 468 | test_repo.populate()?; | ||
| 469 | |||
| 470 | // simulating ammending an older version of the proposal commits on the current | ||
| 471 | // branch | ||
| 472 | create_and_populate_branch( | ||
| 473 | &test_repo, | ||
| 474 | FEATURE_BRANCH_NAME_1, | ||
| 475 | "a-changed", | ||
| 476 | false, | ||
| 477 | )?; | ||
| 478 | |||
| 479 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 480 | p.expect("finding proposal root event...\r\n")?; | ||
| 481 | p.expect("found proposal root event. finding commits...\r\n")?; | ||
| 482 | p.expect( | ||
| 483 | "you have an ammended/rebase version the proposal that is unpublished\r\n", | ||
| 484 | )?; | ||
| 485 | p.expect("your local proposal branch (2 ahead 0 behind 'main') has conflicting changes with the latest published proposal (2 ahead 0 behind 'main')\r\n")?; | ||
| 486 | p.expect("its likely that you have rebased / ammended an old proposal version because git has no record of the latest proposal commit.\r\n")?; | ||
| 487 | p.expect("it is possible that you have been working off the latest version and git has delete this commit as part of a clean up\r\n")?; | ||
| 488 | p.expect("to view the latest proposal but retain your changes:\r\n")?; | ||
| 489 | p.expect(" 1) create a new branch off the tip commit of this one to store your changes\r\n")?; | ||
| 490 | p.expect(" 2) run `ngit list` and checkout the latest published version of this proposal\r\n")?; | ||
| 491 | p.expect("if you are confident in your changes consider running `ngit push --force`\r\n")?; | ||
| 492 | p.expect_end()?; | ||
| 493 | |||
| 494 | for p in [51, 52, 53, 55, 56] { | ||
| 495 | relay::shutdown_relay(8000 + p)?; | ||
| 496 | } | ||
| 497 | Ok(()) | ||
| 498 | }); | ||
| 499 | |||
| 500 | // launch relay | ||
| 501 | let _ = join!( | ||
| 502 | r51.listen_until_close(), | ||
| 503 | r52.listen_until_close(), | ||
| 504 | r53.listen_until_close(), | ||
| 505 | r55.listen_until_close(), | ||
| 506 | r56.listen_until_close(), | ||
| 507 | ); | ||
| 508 | cli_tester_handle.join().unwrap()?; | ||
| 509 | println!("{:?}", r55.events); | ||
| 510 | Ok(()) | ||
| 511 | } | ||
| 512 | |||
| 513 | #[tokio::test] | ||
| 514 | #[serial] | ||
| 515 | async fn cli_output_correct() -> Result<()> { | ||
| 516 | let _ = run_async_prompts_to_choose_from_proposal_titles().await; | ||
| 517 | Ok(()) | ||
| 518 | } | ||
| 519 | } | ||
| 520 | } | ||
| 521 | |||
| 522 | mod when_latest_proposal_ammended_locally { | ||
| 523 | use super::*; | ||
| 524 | |||
| 525 | mod cli_prompts { | ||
| 526 | use super::*; | ||
| 527 | async fn run_async_prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 528 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 529 | Relay::new(8051, None, None), | ||
| 530 | Relay::new(8052, None, None), | ||
| 531 | Relay::new(8053, None, None), | ||
| 532 | Relay::new(8055, None, None), | ||
| 533 | Relay::new(8056, None, None), | ||
| 534 | ); | ||
| 535 | |||
| 536 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 537 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 538 | r51.events.push(generate_repo_ref_event()); | ||
| 539 | |||
| 540 | r55.events.push(generate_repo_ref_event()); | ||
| 541 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 542 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 543 | |||
| 544 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 545 | cli_tester_create_proposals()?; | ||
| 546 | |||
| 547 | let test_repo = GitTestRepo::default(); | ||
| 548 | test_repo.populate()?; | ||
| 549 | |||
| 550 | // simulating checking out the proposal (the commits_ids will match) | ||
| 551 | create_and_populate_branch(&test_repo, "different-branch-name", "a", false)?; | ||
| 552 | test_repo.checkout("main")?; | ||
| 553 | // simulating ammending the proposal | ||
| 554 | create_and_populate_branch( | ||
| 555 | &test_repo, | ||
| 556 | FEATURE_BRANCH_NAME_1, | ||
| 557 | "a-changed", | ||
| 558 | false, | ||
| 559 | )?; | ||
| 560 | |||
| 561 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 562 | p.expect("finding proposal root event...\r\n")?; | ||
| 563 | p.expect("found proposal root event. finding commits...\r\n")?; | ||
| 564 | p.expect( | ||
| 565 | "you have an ammended/rebase version the proposal that is unpublished\r\n", | ||
| 566 | )?; | ||
| 567 | p.expect("you have previously applied the latest version of the proposal (2 ahead 0 behind 'main') but your local proposal branch has ammended or rebased it (2 ahead 0 behind 'main')\r\n")?; | ||
| 568 | p.expect("to view the latest proposal but retain your changes:\r\n")?; | ||
| 569 | p.expect(" 1) create a new branch off the tip commit of this one to store your changes\r\n")?; | ||
| 570 | p.expect(" 2) run `ngit list` and checkout the latest published version of this proposal\r\n")?; | ||
| 571 | p.expect("if you are confident in your changes consider running `ngit push --force`\r\n")?; | ||
| 572 | p.expect_end()?; | ||
| 573 | |||
| 574 | for p in [51, 52, 53, 55, 56] { | ||
| 575 | relay::shutdown_relay(8000 + p)?; | ||
| 576 | } | ||
| 577 | Ok(()) | ||
| 578 | }); | ||
| 579 | |||
| 580 | // launch relay | ||
| 581 | let _ = join!( | ||
| 582 | r51.listen_until_close(), | ||
| 583 | r52.listen_until_close(), | ||
| 584 | r53.listen_until_close(), | ||
| 585 | r55.listen_until_close(), | ||
| 586 | r56.listen_until_close(), | ||
| 587 | ); | ||
| 588 | cli_tester_handle.join().unwrap()?; | ||
| 589 | println!("{:?}", r55.events); | ||
| 590 | Ok(()) | ||
| 591 | } | ||
| 592 | |||
| 593 | #[tokio::test] | ||
| 594 | #[serial] | ||
| 595 | async fn cli_output_correct() -> Result<()> { | ||
| 596 | let _ = run_async_prompts_to_choose_from_proposal_titles().await; | ||
| 597 | Ok(()) | ||
| 598 | } | ||
| 599 | } | ||
| 600 | } | ||
| 601 | |||
| 442 | mod when_local_commits_on_uptodate_proposal { | 602 | mod when_local_commits_on_uptodate_proposal { |
| 443 | use super::*; | 603 | use super::*; |
| 444 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | 604 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { |