upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/pull.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-07-24 12:20:42 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-07-24 12:24:55 +0100
commitab8785ef986b583dbded578c5b90435adfca526f (patch)
treedefed6421891932fe0fc6b70e5b34399b37d7279 /tests/pull.rs
parent8d553d29829faaa3978b08811b3e40386b90db50 (diff)
test: refactor `list` and `pull` to abstract code
into lib which makes reading and maintaining tests easier
Diffstat (limited to 'tests/pull.rs')
-rw-r--r--tests/pull.rs188
1 files changed, 19 insertions, 169 deletions
diff --git a/tests/pull.rs b/tests/pull.rs
index 70319bd..89b28c3 100644
--- a/tests/pull.rs
+++ b/tests/pull.rs
@@ -31,7 +31,7 @@ mod when_main_is_checked_out {
31 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 31 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
32 cli_tester_create_proposals()?; 32 cli_tester_create_proposals()?;
33 33
34 let test_repo = create_repo_with_first_proposal_branch_pulled_and_checkedout()?; 34 let test_repo = create_repo_with_proposal_branch_pulled_and_checkedout(1)?;
35 35
36 test_repo.checkout("main")?; 36 test_repo.checkout("main")?;
37 37
@@ -149,7 +149,7 @@ mod when_branch_is_checked_out {
149 149
150 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 150 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
151 let (_, test_repo) = 151 let (_, test_repo) =
152 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 152 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
153 153
154 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 154 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
155 p.expect("fetching updates...\r\n")?; 155 p.expect("fetching updates...\r\n")?;
@@ -201,18 +201,10 @@ mod when_branch_is_checked_out {
201 let cli_tester_handle = 201 let cli_tester_handle =
202 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 202 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> {
203 let (originating_repo, test_repo) = 203 let (originating_repo, test_repo) =
204 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 204 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
205 205
206 // remove latest commit so it is behind 206 remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(
207 let branch_name = test_repo.get_checked_out_branch_name()?; 207 &test_repo,
208 test_repo.checkout("main")?;
209 test_repo.git_repo.branch(
210 &branch_name,
211 &test_repo
212 .git_repo
213 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
214 .parent(0)?,
215 true,
216 )?; 208 )?;
217 209
218 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 210 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
@@ -263,18 +255,10 @@ mod when_branch_is_checked_out {
263 let cli_tester_handle = 255 let cli_tester_handle =
264 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 256 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> {
265 let (originating_repo, test_repo) = 257 let (originating_repo, test_repo) =
266 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 258 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
267 259
268 // remove latest commit so it is behind 260 remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(
269 let branch_name = test_repo.get_checked_out_branch_name()?; 261 &test_repo,
270 test_repo.checkout("main")?;
271 test_repo.git_repo.branch(
272 &branch_name,
273 &test_repo
274 .git_repo
275 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
276 .parent(0)?,
277 true,
278 )?; 262 )?;
279 263
280 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 264 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
@@ -344,24 +328,9 @@ mod when_branch_is_checked_out {
344 328
345 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 329 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
346 let (originating_repo, test_repo) = 330 let (originating_repo, test_repo) =
347 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 331 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
348 332
349 // remove latest commit so it is behind 333 let branch_name = ammend_last_commit_and_checkout_main(&test_repo)?;
350 let branch_name = test_repo.get_checked_out_branch_name()?;
351 test_repo.checkout("main")?;
352 test_repo.git_repo.branch(
353 &branch_name,
354 &test_repo
355 .git_repo
356 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
357 .parent(0)?,
358 true,
359 )?;
360 // add another commit (so we have an ammened local branch)
361 test_repo.checkout(&branch_name)?;
362 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
363 test_repo.stage_and_commit("add ammended-commit.md")?;
364 test_repo.checkout("main")?;
365 334
366 // create and send a revision from another repository 335 // create and send a revision from another repository
367 originating_repo.checkout("main")?; 336 originating_repo.checkout("main")?;
@@ -443,24 +412,9 @@ mod when_branch_is_checked_out {
443 412
444 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 413 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
445 let (_, test_repo) = 414 let (_, test_repo) =
446 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 415 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
447 416
448 // remove latest commit so it is behind 417 ammend_last_commit_and_checkout_main(&test_repo)?;
449 let branch_name = test_repo.get_checked_out_branch_name()?;
450 test_repo.checkout("main")?;
451 test_repo.git_repo.branch(
452 &branch_name,
453 &test_repo
454 .git_repo
455 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
456 .parent(0)?,
457 true,
458 )?;
459 // add another commit (so we have an ammened local branch)
460 test_repo.checkout(&branch_name)?;
461 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
462 test_repo.stage_and_commit("add ammended-commit.md")?;
463 test_repo.checkout("main")?;
464 418
465 // run test 419 // run test
466 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 420 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
@@ -520,7 +474,7 @@ mod when_branch_is_checked_out {
520 let cli_tester_handle = std::thread::spawn( 474 let cli_tester_handle = std::thread::spawn(
521 move || -> Result<(GitTestRepo, GitTestRepo)> { 475 move || -> Result<(GitTestRepo, GitTestRepo)> {
522 let (originating_repo, test_repo) = 476 let (originating_repo, test_repo) =
523 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 477 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
524 478
525 // add another commit (so we have a local branch 1 ahead) 479 // add another commit (so we have a local branch 1 ahead)
526 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; 480 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
@@ -578,7 +532,7 @@ mod when_branch_is_checked_out {
578 532
579 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 533 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
580 let (_, test_repo) = 534 let (_, test_repo) =
581 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 535 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
582 536
583 // add another commit (so we have a local branch 1 ahead) 537 // add another commit (so we have a local branch 1 ahead)
584 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; 538 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
@@ -627,10 +581,7 @@ mod when_branch_is_checked_out {
627 } 581 }
628 } 582 }
629 mod when_latest_event_rebases_branch { 583 mod when_latest_event_rebases_branch {
630 use std::time::Duration; 584 use tokio::task::JoinHandle;
631
632 use nostr_sdk::Client;
633 use tokio::{runtime::Handle, task::JoinHandle};
634 585
635 use super::*; 586 use super::*;
636 587
@@ -654,57 +605,7 @@ mod when_branch_is_checked_out {
654 605
655 let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> = 606 let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> =
656 tokio::task::spawn_blocking(move || { 607 tokio::task::spawn_blocking(move || {
657 let (_, test_repo) = 608 let (originating_repo, test_repo) = create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebased_proposal()?;
658 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
659
660 // get proposal id of first
661 let client = Client::default();
662 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
663 Handle::current().block_on(client.connect_relay("ws://localhost:8055"))?;
664 let proposals = Handle::current().block_on(client.get_events_of(
665 vec![
666 nostr::Filter::default()
667 .kind(nostr::Kind::Custom(PATCH_KIND))
668 .custom_tag(
669 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T),
670 vec!["root"],
671 ),
672 ],
673 Some(Duration::from_millis(500)),
674 ))?;
675 Handle::current().block_on(client.disconnect())?;
676
677 let proposal_1_id = proposals
678 .iter()
679 .find(|e| {
680 e.tags
681 .iter()
682 .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1))
683 })
684 .unwrap()
685 .id;
686 // recreate proposal 1 on top of a another commit (like a rebase on top
687 // of one extra commit)
688 let second_originating_repo = GitTestRepo::default();
689 second_originating_repo.populate()?;
690 std::fs::write(
691 second_originating_repo.dir.join("amazing.md"),
692 "some content",
693 )?;
694 second_originating_repo.stage_and_commit("commit for rebasing on top of")?;
695 cli_tester_create_proposal(
696 &second_originating_repo,
697 FEATURE_BRANCH_NAME_1,
698 "a",
699 Some((PROPOSAL_TITLE_1, "proposal a description")),
700 Some(proposal_1_id.to_string()),
701 )?;
702
703 // pretend we have pulled the updated main branch
704 test_repo.checkout("main")?;
705 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
706 test_repo.stage_and_commit("commit for rebasing on top of")?;
707 test_repo.checkout(FEATURE_BRANCH_NAME_1)?;
708 609
709 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 610 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
710 p.expect_end_eventually_and_print()?; 611 p.expect_end_eventually_and_print()?;
@@ -712,7 +613,7 @@ mod when_branch_is_checked_out {
712 for p in [51, 52, 53, 55, 56] { 613 for p in [51, 52, 53, 55, 56] {
713 relay::shutdown_relay(8000 + p)?; 614 relay::shutdown_relay(8000 + p)?;
714 } 615 }
715 Ok((second_originating_repo, test_repo)) 616 Ok((originating_repo, test_repo))
716 }); 617 });
717 618
718 // launch relay 619 // launch relay
@@ -752,58 +653,7 @@ mod when_branch_is_checked_out {
752 653
753 let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking( 654 let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking(
754 move || { 655 move || {
755 let (_, test_repo) = 656 let (_, test_repo) = create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebased_proposal()?;
756 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
757
758 // get proposal id of first
759 let client = Client::default();
760 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
761 Handle::current().block_on(client.connect_relay("ws://localhost:8055"))?;
762 let proposals = Handle::current().block_on(client.get_events_of(
763 vec![
764 nostr::Filter::default()
765 .kind(nostr::Kind::Custom(PATCH_KIND))
766 .custom_tag(
767 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T),
768 vec!["root"],
769 ),
770 ],
771 Some(Duration::from_millis(500)),
772 ))?;
773 Handle::current().block_on(client.disconnect())?;
774
775 let proposal_1_id = proposals
776 .iter()
777 .find(|e| {
778 e.tags
779 .iter()
780 .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1))
781 })
782 .unwrap()
783 .id;
784 // recreate proposal 1 on top of a another commit (like a rebase on top
785 // of one extra commit)
786 let second_originating_repo = GitTestRepo::default();
787 second_originating_repo.populate()?;
788 std::fs::write(
789 second_originating_repo.dir.join("amazing.md"),
790 "some content",
791 )?;
792 second_originating_repo
793 .stage_and_commit("commit for rebasing on top of")?;
794 cli_tester_create_proposal(
795 &second_originating_repo,
796 FEATURE_BRANCH_NAME_1,
797 "a",
798 Some((PROPOSAL_TITLE_1, "proposal a description")),
799 Some(proposal_1_id.to_string()),
800 )?;
801
802 // pretend we have pulled the updated main branch
803 test_repo.checkout("main")?;
804 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
805 test_repo.stage_and_commit("commit for rebasing on top of")?;
806 test_repo.checkout(FEATURE_BRANCH_NAME_1)?;
807 657
808 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 658 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
809 p.expect("fetching updates...\r\n")?; 659 p.expect("fetching updates...\r\n")?;