upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/list.rs235
-rw-r--r--tests/pull.rs168
2 files changed, 208 insertions, 195 deletions
diff --git a/tests/list.rs b/tests/list.rs
index ee5e1dc..8252448 100644
--- a/tests/list.rs
+++ b/tests/list.rs
@@ -1,6 +1,6 @@
1use anyhow::Result; 1use anyhow::Result;
2use futures::join; 2use futures::join;
3use nostr_sdk::client::blocking::Client; 3use nostr_sdk::client::Client;
4use serial_test::serial; 4use serial_test::serial;
5use test_utils::{git::GitTestRepo, relay::Relay, *}; 5use test_utils::{git::GitTestRepo, relay::Relay, *};
6 6
@@ -1589,6 +1589,8 @@ mod when_main_branch_is_uptodate {
1589 mod when_latest_revision_rebases_branch { 1589 mod when_latest_revision_rebases_branch {
1590 use std::time::Duration; 1590 use std::time::Duration;
1591 1591
1592 use tokio::{runtime::Handle, task::JoinHandle};
1593
1592 use super::*; 1594 use super::*;
1593 1595
1594 async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { 1596 async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> {
@@ -1609,26 +1611,28 @@ mod when_main_branch_is_uptodate {
1609 r55.events.push(generate_test_key_1_metadata_event("fred")); 1611 r55.events.push(generate_test_key_1_metadata_event("fred"));
1610 r55.events.push(generate_test_key_1_relay_list_event()); 1612 r55.events.push(generate_test_key_1_relay_list_event());
1611 1613
1612 let cli_tester_handle = std::thread::spawn( 1614 let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> =
1613 move || -> Result<(GitTestRepo, GitTestRepo)> { 1615 tokio::task::spawn_blocking(move || {
1614 // create 3 proposals 1616 // create 3 proposals
1615 let _ = cli_tester_create_proposals()?; 1617 let _ = cli_tester_create_proposals()?;
1616 // get proposal id of first 1618 // get proposal id of first
1617 let client = Client::new(&nostr::Keys::generate()); 1619 // get proposal id of first
1618 client.add_relay("ws://localhost:8055")?; 1620 let client = Client::default();
1619 client.connect_relay("ws://localhost:8055")?; 1621 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
1620 let proposals = client.get_events_of( 1622 Handle::current()
1623 .block_on(client.connect_relay("ws://localhost:8055"))?;
1624 let proposals = Handle::current().block_on(client.get_events_of(
1621 vec![ 1625 vec![
1622 nostr::Filter::default() 1626 nostr::Filter::default()
1623 .kind(nostr::Kind::Custom(PATCH_KIND)) 1627 .kind(nostr::Kind::Custom(PATCH_KIND))
1624 .custom_tag( 1628 .custom_tag(
1625 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), 1629 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T),
1626 vec!["root"], 1630 vec!["root"],
1627 ), 1631 ),
1628 ], 1632 ],
1629 Some(Duration::from_millis(500)), 1633 Some(Duration::from_millis(500)),
1630 )?; 1634 ))?;
1631 client.disconnect()?; 1635 Handle::current().block_on(client.disconnect())?;
1632 1636
1633 let proposal_1_id = proposals 1637 let proposal_1_id = proposals
1634 .iter() 1638 .iter()
@@ -1702,8 +1706,7 @@ mod when_main_branch_is_uptodate {
1702 relay::shutdown_relay(8000 + p)?; 1706 relay::shutdown_relay(8000 + p)?;
1703 } 1707 }
1704 Ok((second_originating_repo, test_repo)) 1708 Ok((second_originating_repo, test_repo))
1705 }, 1709 });
1706 );
1707 1710
1708 // launch relay 1711 // launch relay
1709 let _ = join!( 1712 let _ = join!(
@@ -1713,7 +1716,7 @@ mod when_main_branch_is_uptodate {
1713 r55.listen_until_close(), 1716 r55.listen_until_close(),
1714 r56.listen_until_close(), 1717 r56.listen_until_close(),
1715 ); 1718 );
1716 let res = cli_tester_handle.join().unwrap()?; 1719 let res = cli_tester_handle.await??;
1717 1720
1718 Ok(res) 1721 Ok(res)
1719 } 1722 }
@@ -1740,99 +1743,105 @@ mod when_main_branch_is_uptodate {
1740 r55.events.push(generate_test_key_1_metadata_event("fred")); 1743 r55.events.push(generate_test_key_1_metadata_event("fred"));
1741 r55.events.push(generate_test_key_1_relay_list_event()); 1744 r55.events.push(generate_test_key_1_relay_list_event());
1742 1745
1743 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 1746 let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking(
1744 // create 3 proposals 1747 move || {
1745 let _ = cli_tester_create_proposals()?; 1748 // create 3 proposals
1746 // get proposal id of first 1749 let _ = cli_tester_create_proposals()?;
1747 let client = Client::new(&nostr::Keys::generate()); 1750 // get proposal id of first
1748 client.add_relay("ws://localhost:8055")?; 1751 let client = Client::default();
1749 client.connect_relay("ws://localhost:8055")?; 1752 Handle::current()
1750 let proposals = client.get_events_of( 1753 .block_on(client.add_relay("ws://localhost:8055"))?;
1751 vec![ 1754 Handle::current()
1752 nostr::Filter::default() 1755 .block_on(client.connect_relay("ws://localhost:8055"))?;
1753 .kind(nostr::Kind::Custom(PATCH_KIND)) 1756 let proposals =
1754 .custom_tag( 1757 Handle::current().block_on(client.get_events_of(
1755 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), 1758 vec![
1756 vec!["root"], 1759 nostr::Filter::default()
1757 ), 1760 .kind(nostr::Kind::Custom(PATCH_KIND))
1758 ], 1761 .custom_tag(
1759 Some(Duration::from_millis(500)), 1762 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T),
1760 )?; 1763 vec!["root"],
1761 client.disconnect()?; 1764 ),
1762 1765 ],
1763 let proposal_1_id = proposals 1766 Some(Duration::from_millis(500)),
1764 .iter() 1767 ))?;
1765 .find(|e| { 1768 Handle::current().block_on(client.disconnect())?;
1766 e.tags 1769
1767 .iter() 1770 let proposal_1_id = proposals
1768 .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1)) 1771 .iter()
1769 }) 1772 .find(|e| {
1770 .unwrap() 1773 e.tags
1771 .id; 1774 .iter()
1772 // recreate proposal 1 on top of a another commit (like a rebase on top 1775 .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1))
1773 // of one extra commit) 1776 })
1774 let second_originating_repo = GitTestRepo::default(); 1777 .unwrap()
1775 second_originating_repo.populate()?; 1778 .id;
1776 std::fs::write( 1779 // recreate proposal 1 on top of a another commit (like a rebase on
1777 second_originating_repo.dir.join("amazing.md"), 1780 // top of one extra commit)
1778 "some content", 1781 let second_originating_repo = GitTestRepo::default();
1779 )?; 1782 second_originating_repo.populate()?;
1780 second_originating_repo 1783 std::fs::write(
1781 .stage_and_commit("commit for rebasing on top of")?; 1784 second_originating_repo.dir.join("amazing.md"),
1782 cli_tester_create_proposal( 1785 "some content",
1783 &second_originating_repo, 1786 )?;
1784 FEATURE_BRANCH_NAME_1, 1787 second_originating_repo
1785 "a", 1788 .stage_and_commit("commit for rebasing on top of")?;
1786 Some((PROPOSAL_TITLE_1, "proposal a description")), 1789 cli_tester_create_proposal(
1787 Some(proposal_1_id.to_string()), 1790 &second_originating_repo,
1788 )?; 1791 FEATURE_BRANCH_NAME_1,
1789 1792 "a",
1790 // pretend we have downloaded the origianl version of the first proposal 1793 Some((PROPOSAL_TITLE_1, "proposal a description")),
1791 let test_repo = GitTestRepo::default(); 1794 Some(proposal_1_id.to_string()),
1792 test_repo.populate()?; 1795 )?;
1793 create_and_populate_branch( 1796
1794 &test_repo, 1797 // pretend we have downloaded the origianl version of the first
1795 FEATURE_BRANCH_NAME_1, 1798 // proposal
1796 "a", 1799 let test_repo = GitTestRepo::default();
1797 false, 1800 test_repo.populate()?;
1798 )?; 1801 create_and_populate_branch(
1799 // pretend we have pulled the updated main branch 1802 &test_repo,
1800 test_repo.checkout("main")?; 1803 FEATURE_BRANCH_NAME_1,
1801 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; 1804 "a",
1802 test_repo.stage_and_commit("commit for rebasing on top of")?; 1805 false,
1803 1806 )?;
1804 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1807 // pretend we have pulled the updated main branch
1805 p.expect("finding proposals...\r\n")?; 1808 test_repo.checkout("main")?;
1806 let mut c = p.expect_choice( 1809 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
1807 "all proposals", 1810 test_repo.stage_and_commit("commit for rebasing on top of")?;
1808 vec![ 1811
1809 format!("\"{PROPOSAL_TITLE_3}\""), 1812 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1810 format!("\"{PROPOSAL_TITLE_2}\""), 1813 p.expect("finding proposals...\r\n")?;
1811 format!("\"{PROPOSAL_TITLE_1}\""), 1814 let mut c = p.expect_choice(
1812 ], 1815 "all proposals",
1813 )?; 1816 vec![
1814 c.succeeds_with(2, true, None)?; 1817 format!("\"{PROPOSAL_TITLE_3}\""),
1815 p.expect("finding commits...\r\n")?; 1818 format!("\"{PROPOSAL_TITLE_2}\""),
1816 p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; 1819 format!("\"{PROPOSAL_TITLE_1}\""),
1817 let mut c = p.expect_choice( 1820 ],
1818 "", 1821 )?;
1819 vec![ 1822 c.succeeds_with(2, true, None)?;
1820 format!("checkout and overwrite existing proposal branch"), 1823 p.expect("finding commits...\r\n")?;
1821 format!("checkout existing outdated proposal branch"), 1824 p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?;
1822 format!("apply to current branch with `git am`"), 1825 let mut c = p.expect_choice(
1823 format!("download to ./patches"), 1826 "",
1824 format!("back"), 1827 vec![
1825 ], 1828 format!("checkout and overwrite existing proposal branch"),
1826 )?; 1829 format!("checkout existing outdated proposal branch"),
1827 c.succeeds_with(0, false, Some(0))?; 1830 format!("apply to current branch with `git am`"),
1828 p.expect("checked out new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; 1831 format!("download to ./patches"),
1829 p.expect_end()?; 1832 format!("back"),
1830 1833 ],
1831 for p in [51, 52, 53, 55, 56] { 1834 )?;
1832 relay::shutdown_relay(8000 + p)?; 1835 c.succeeds_with(0, false, Some(0))?;
1833 } 1836 p.expect("checked out new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?;
1834 Ok(()) 1837 p.expect_end()?;
1835 }); 1838
1839 for p in [51, 52, 53, 55, 56] {
1840 relay::shutdown_relay(8000 + p)?;
1841 }
1842 Ok(())
1843 },
1844 );
1836 1845
1837 // launch relay 1846 // launch relay
1838 let _ = join!( 1847 let _ = join!(
@@ -1842,7 +1851,7 @@ mod when_main_branch_is_uptodate {
1842 r55.listen_until_close(), 1851 r55.listen_until_close(),
1843 r56.listen_until_close(), 1852 r56.listen_until_close(),
1844 ); 1853 );
1845 cli_tester_handle.join().unwrap()?; 1854 cli_tester_handle.await??;
1846 println!("{:?}", r55.events); 1855 println!("{:?}", r55.events);
1847 Ok(()) 1856 Ok(())
1848 } 1857 }
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 }