diff options
Diffstat (limited to 'tests/pull.rs')
| -rw-r--r-- | tests/pull.rs | 168 |
1 files changed, 86 insertions, 82 deletions
diff --git a/tests/pull.rs b/tests/pull.rs index 853f518..bf132e7 100644 --- a/tests/pull.rs +++ b/tests/pull.rs | |||
| @@ -712,7 +712,8 @@ mod when_branch_is_checked_out { | |||
| 712 | mod when_latest_event_rebases_branch { | 712 | mod when_latest_event_rebases_branch { |
| 713 | use std::time::Duration; | 713 | use std::time::Duration; |
| 714 | 714 | ||
| 715 | use nostr_sdk::blocking::Client; | 715 | use nostr_sdk::Client; |
| 716 | use tokio::{runtime::Handle, task::JoinHandle}; | ||
| 716 | 717 | ||
| 717 | use super::*; | 718 | use super::*; |
| 718 | 719 | ||
| @@ -734,26 +735,26 @@ mod when_branch_is_checked_out { | |||
| 734 | r55.events.push(generate_test_key_1_metadata_event("fred")); | 735 | r55.events.push(generate_test_key_1_metadata_event("fred")); |
| 735 | r55.events.push(generate_test_key_1_relay_list_event()); | 736 | r55.events.push(generate_test_key_1_relay_list_event()); |
| 736 | 737 | ||
| 737 | let cli_tester_handle = | 738 | let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> = |
| 738 | std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { | 739 | tokio::task::spawn_blocking(move || { |
| 739 | // create 3 proposals | 740 | // create 3 proposals |
| 740 | let _ = cli_tester_create_proposals()?; | 741 | let _ = cli_tester_create_proposals()?; |
| 741 | // get proposal id of first | 742 | // get proposal id of first |
| 742 | let client = Client::new(&nostr::Keys::generate()); | 743 | let client = Client::default(); |
| 743 | client.add_relay("ws://localhost:8055")?; | 744 | Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; |
| 744 | client.connect_relay("ws://localhost:8055")?; | 745 | Handle::current().block_on(client.connect_relay("ws://localhost:8055"))?; |
| 745 | let proposals = client.get_events_of( | 746 | let proposals = Handle::current().block_on(client.get_events_of( |
| 746 | vec![ | 747 | vec![ |
| 747 | nostr::Filter::default() | 748 | nostr::Filter::default() |
| 748 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 749 | .kind(nostr::Kind::Custom(PATCH_KIND)) |
| 749 | .custom_tag( | 750 | .custom_tag( |
| 750 | nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), | 751 | nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), |
| 751 | vec!["root"], | 752 | vec!["root"], |
| 752 | ), | 753 | ), |
| 753 | ], | 754 | ], |
| 754 | Some(Duration::from_millis(500)), | 755 | Some(Duration::from_millis(500)), |
| 755 | )?; | 756 | ))?; |
| 756 | client.disconnect()?; | 757 | Handle::current().block_on(client.disconnect())?; |
| 757 | 758 | ||
| 758 | let proposal_1_id = proposals | 759 | let proposal_1_id = proposals |
| 759 | .iter() | 760 | .iter() |
| @@ -808,7 +809,7 @@ mod when_branch_is_checked_out { | |||
| 808 | r55.listen_until_close(), | 809 | r55.listen_until_close(), |
| 809 | r56.listen_until_close(), | 810 | r56.listen_until_close(), |
| 810 | ); | 811 | ); |
| 811 | let res = cli_tester_handle.join().unwrap()?; | 812 | let res = cli_tester_handle.await??; |
| 812 | 813 | ||
| 813 | Ok(res) | 814 | Ok(res) |
| 814 | } | 815 | } |
| @@ -835,72 +836,75 @@ mod when_branch_is_checked_out { | |||
| 835 | r55.events.push(generate_test_key_1_metadata_event("fred")); | 836 | r55.events.push(generate_test_key_1_metadata_event("fred")); |
| 836 | r55.events.push(generate_test_key_1_relay_list_event()); | 837 | r55.events.push(generate_test_key_1_relay_list_event()); |
| 837 | 838 | ||
| 838 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 839 | let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking( |
| 839 | // create 3 proposals | 840 | move || { |
| 840 | let _ = cli_tester_create_proposals()?; | 841 | // create 3 proposals |
| 841 | // get proposal id of first | 842 | let _ = cli_tester_create_proposals()?; |
| 842 | let client = Client::new(&nostr::Keys::generate()); | 843 | // get proposal id of first |
| 843 | client.add_relay("ws://localhost:8055")?; | 844 | let client = Client::default(); |
| 844 | client.connect_relay("ws://localhost:8055")?; | 845 | Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; |
| 845 | let proposals = client.get_events_of( | 846 | Handle::current().block_on(client.connect_relay("ws://localhost:8055"))?; |
| 846 | vec![ | 847 | let proposals = Handle::current().block_on(client.get_events_of( |
| 847 | nostr::Filter::default() | 848 | vec![ |
| 848 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 849 | nostr::Filter::default() |
| 849 | .custom_tag( | 850 | .kind(nostr::Kind::Custom(PATCH_KIND)) |
| 850 | nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), | 851 | .custom_tag( |
| 851 | vec!["root"], | 852 | nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), |
| 852 | ), | 853 | vec!["root"], |
| 853 | ], | 854 | ), |
| 854 | Some(Duration::from_millis(500)), | 855 | ], |
| 855 | )?; | 856 | Some(Duration::from_millis(500)), |
| 856 | client.disconnect()?; | 857 | ))?; |
| 857 | 858 | Handle::current().block_on(client.disconnect())?; | |
| 858 | let proposal_1_id = proposals | 859 | |
| 859 | .iter() | 860 | let proposal_1_id = proposals |
| 860 | .find(|e| { | 861 | .iter() |
| 861 | e.tags | 862 | .find(|e| { |
| 862 | .iter() | 863 | e.tags |
| 863 | .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1)) | 864 | .iter() |
| 864 | }) | 865 | .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1)) |
| 865 | .unwrap() | 866 | }) |
| 866 | .id; | 867 | .unwrap() |
| 867 | // recreate proposal 1 on top of a another commit (like a rebase on top | 868 | .id; |
| 868 | // of one extra commit) | 869 | // recreate proposal 1 on top of a another commit (like a rebase on top |
| 869 | let second_originating_repo = GitTestRepo::default(); | 870 | // of one extra commit) |
| 870 | second_originating_repo.populate()?; | 871 | let second_originating_repo = GitTestRepo::default(); |
| 871 | std::fs::write( | 872 | second_originating_repo.populate()?; |
| 872 | second_originating_repo.dir.join("amazing.md"), | 873 | std::fs::write( |
| 873 | "some content", | 874 | second_originating_repo.dir.join("amazing.md"), |
| 874 | )?; | 875 | "some content", |
| 875 | second_originating_repo.stage_and_commit("commit for rebasing on top of")?; | 876 | )?; |
| 876 | cli_tester_create_proposal( | 877 | second_originating_repo |
| 877 | &second_originating_repo, | 878 | .stage_and_commit("commit for rebasing on top of")?; |
| 878 | FEATURE_BRANCH_NAME_1, | 879 | cli_tester_create_proposal( |
| 879 | "a", | 880 | &second_originating_repo, |
| 880 | Some((PROPOSAL_TITLE_1, "proposal a description")), | 881 | FEATURE_BRANCH_NAME_1, |
| 881 | Some(proposal_1_id.to_string()), | 882 | "a", |
| 882 | )?; | 883 | Some((PROPOSAL_TITLE_1, "proposal a description")), |
| 883 | 884 | Some(proposal_1_id.to_string()), | |
| 884 | // pretend we have downloaded the origianl version of the first proposal | 885 | )?; |
| 885 | let test_repo = GitTestRepo::default(); | 886 | |
| 886 | test_repo.populate()?; | 887 | // pretend we have downloaded the origianl version of the first proposal |
| 887 | create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; | 888 | let test_repo = GitTestRepo::default(); |
| 888 | // pretend we have pulled the updated main branch | 889 | test_repo.populate()?; |
| 889 | test_repo.checkout("main")?; | 890 | create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; |
| 890 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | 891 | // pretend we have pulled the updated main branch |
| 891 | test_repo.stage_and_commit("commit for rebasing on top of")?; | 892 | test_repo.checkout("main")?; |
| 892 | test_repo.checkout(FEATURE_BRANCH_NAME_1)?; | 893 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; |
| 894 | test_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 895 | test_repo.checkout(FEATURE_BRANCH_NAME_1)?; | ||
| 893 | 896 | ||
| 894 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | 897 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); |
| 895 | p.expect("finding proposal root event...\r\n")?; | 898 | p.expect("finding proposal root event...\r\n")?; |
| 896 | p.expect("found proposal root event. finding commits...\r\n")?; | 899 | p.expect("found proposal root event. finding commits...\r\n")?; |
| 897 | p.expect_end_with("pulled new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; | 900 | p.expect_end_with("pulled new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; |
| 898 | 901 | ||
| 899 | for p in [51, 52, 53, 55, 56] { | 902 | for p in [51, 52, 53, 55, 56] { |
| 900 | relay::shutdown_relay(8000 + p)?; | 903 | relay::shutdown_relay(8000 + p)?; |
| 901 | } | 904 | } |
| 902 | Ok(()) | 905 | Ok(()) |
| 903 | }); | 906 | }, |
| 907 | ); | ||
| 904 | 908 | ||
| 905 | // launch relay | 909 | // launch relay |
| 906 | let _ = join!( | 910 | let _ = join!( |
| @@ -910,7 +914,7 @@ mod when_branch_is_checked_out { | |||
| 910 | r55.listen_until_close(), | 914 | r55.listen_until_close(), |
| 911 | r56.listen_until_close(), | 915 | r56.listen_until_close(), |
| 912 | ); | 916 | ); |
| 913 | cli_tester_handle.join().unwrap()?; | 917 | cli_tester_handle.await??; |
| 914 | println!("{:?}", r55.events); | 918 | println!("{:?}", r55.events); |
| 915 | Ok(()) | 919 | Ok(()) |
| 916 | } | 920 | } |