upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/list.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/list.rs')
-rw-r--r--tests/list.rs235
1 files changed, 122 insertions, 113 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 }