diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-03-28 12:35:37 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-03-28 12:35:37 +0000 |
| commit | 4b06b2bd70d37656d727c8fffc0656c1aa3c7b97 (patch) | |
| tree | 1d885fdef21a7530c1a91f848788a665d6fc9948 /tests/list.rs | |
| parent | 91a68de459b7d22a8dfb8a324e43740fca3e0a35 (diff) | |
| parent | 11dc9fa2d8b82594d3803f12d2c5a49e57026cfb (diff) | |
Merge upgrade rust-nostr v0.29
refactor to address breaking changes in rust-nostr
fix a number of in dependancy which have been upstreamed
Diffstat (limited to 'tests/list.rs')
| -rw-r--r-- | tests/list.rs | 238 |
1 files changed, 128 insertions, 110 deletions
diff --git a/tests/list.rs b/tests/list.rs index 4f55645..61c2201 100644 --- a/tests/list.rs +++ b/tests/list.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use anyhow::Result; | 1 | use anyhow::Result; |
| 2 | use futures::join; | 2 | use futures::join; |
| 3 | use nostr_sdk::client::blocking::Client; | 3 | use nostr_sdk::client::Client; |
| 4 | use serial_test::serial; | 4 | use serial_test::serial; |
| 5 | use test_utils::{git::GitTestRepo, relay::Relay, *}; | 5 | use test_utils::{git::GitTestRepo, relay::Relay, *}; |
| 6 | 6 | ||
| @@ -23,6 +23,7 @@ fn cli_tester_create_proposals() -> Result<GitTestRepo> { | |||
| 23 | Some((PROPOSAL_TITLE_1, "proposal a description")), | 23 | Some((PROPOSAL_TITLE_1, "proposal a description")), |
| 24 | None, | 24 | None, |
| 25 | )?; | 25 | )?; |
| 26 | std::thread::sleep(std::time::Duration::from_millis(1000)); | ||
| 26 | cli_tester_create_proposal( | 27 | cli_tester_create_proposal( |
| 27 | &git_repo, | 28 | &git_repo, |
| 28 | FEATURE_BRANCH_NAME_2, | 29 | FEATURE_BRANCH_NAME_2, |
| @@ -30,6 +31,7 @@ fn cli_tester_create_proposals() -> Result<GitTestRepo> { | |||
| 30 | Some((PROPOSAL_TITLE_2, "proposal b description")), | 31 | Some((PROPOSAL_TITLE_2, "proposal b description")), |
| 31 | None, | 32 | None, |
| 32 | )?; | 33 | )?; |
| 34 | std::thread::sleep(std::time::Duration::from_millis(1000)); | ||
| 33 | cli_tester_create_proposal( | 35 | cli_tester_create_proposal( |
| 34 | &git_repo, | 36 | &git_repo, |
| 35 | FEATURE_BRANCH_NAME_3, | 37 | FEATURE_BRANCH_NAME_3, |
| @@ -72,7 +74,7 @@ fn cli_tester_create_proposal( | |||
| 72 | in_reply_to: Option<String>, | 74 | in_reply_to: Option<String>, |
| 73 | ) -> Result<()> { | 75 | ) -> Result<()> { |
| 74 | create_and_populate_branch(test_repo, branch_name, prefix, false)?; | 76 | create_and_populate_branch(test_repo, branch_name, prefix, false)?; |
| 75 | 77 | std::thread::sleep(std::time::Duration::from_millis(1000)); | |
| 76 | if let Some(in_reply_to) = in_reply_to { | 78 | if let Some(in_reply_to) = in_reply_to { |
| 77 | let mut p = CliTester::new_from_dir( | 79 | let mut p = CliTester::new_from_dir( |
| 78 | &test_repo.dir, | 80 | &test_repo.dir, |
| @@ -190,7 +192,7 @@ mod cannot_find_repo_event { | |||
| 190 | input.succeeds_with( | 192 | input.succeeds_with( |
| 191 | &Coordinate { | 193 | &Coordinate { |
| 192 | kind: nostr::Kind::Custom(REPOSITORY_KIND), | 194 | kind: nostr::Kind::Custom(REPOSITORY_KIND), |
| 193 | pubkey: TEST_KEY_1_KEYS.public_key(), | 195 | public_key: TEST_KEY_1_KEYS.public_key(), |
| 194 | identifier: repo_event.identifier().unwrap().to_string(), | 196 | identifier: repo_event.identifier().unwrap().to_string(), |
| 195 | relays: vec!["ws://localhost:8056".to_string()], | 197 | relays: vec!["ws://localhost:8056".to_string()], |
| 196 | } | 198 | } |
| @@ -489,7 +491,7 @@ mod when_main_branch_is_uptodate { | |||
| 489 | "checked out proposal as '{FEATURE_BRANCH_NAME_3}' branch\r\n" | 491 | "checked out proposal as '{FEATURE_BRANCH_NAME_3}' branch\r\n" |
| 490 | ))?; | 492 | ))?; |
| 491 | p.expect_end()?; | 493 | p.expect_end()?; |
| 492 | 494 | println!("blablagothere"); | |
| 493 | for p in [51, 52, 53, 55, 56] { | 495 | for p in [51, 52, 53, 55, 56] { |
| 494 | relay::shutdown_relay(8000 + p)?; | 496 | relay::shutdown_relay(8000 + p)?; |
| 495 | } | 497 | } |
| @@ -726,6 +728,7 @@ mod when_main_branch_is_uptodate { | |||
| 726 | 728 | ||
| 727 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 729 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 728 | let originating_repo = cli_tester_create_proposals()?; | 730 | let originating_repo = cli_tester_create_proposals()?; |
| 731 | std::thread::sleep(std::time::Duration::from_millis(1000)); | ||
| 729 | cli_tester_create_proposal( | 732 | cli_tester_create_proposal( |
| 730 | &originating_repo, | 733 | &originating_repo, |
| 731 | FEATURE_BRANCH_NAME_4, | 734 | FEATURE_BRANCH_NAME_4, |
| @@ -1589,6 +1592,8 @@ mod when_main_branch_is_uptodate { | |||
| 1589 | mod when_latest_revision_rebases_branch { | 1592 | mod when_latest_revision_rebases_branch { |
| 1590 | use std::time::Duration; | 1593 | use std::time::Duration; |
| 1591 | 1594 | ||
| 1595 | use tokio::{runtime::Handle, task::JoinHandle}; | ||
| 1596 | |||
| 1592 | use super::*; | 1597 | use super::*; |
| 1593 | 1598 | ||
| 1594 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | 1599 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { |
| @@ -1609,23 +1614,28 @@ mod when_main_branch_is_uptodate { | |||
| 1609 | r55.events.push(generate_test_key_1_metadata_event("fred")); | 1614 | r55.events.push(generate_test_key_1_metadata_event("fred")); |
| 1610 | r55.events.push(generate_test_key_1_relay_list_event()); | 1615 | r55.events.push(generate_test_key_1_relay_list_event()); |
| 1611 | 1616 | ||
| 1612 | let cli_tester_handle = std::thread::spawn( | 1617 | let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> = |
| 1613 | move || -> Result<(GitTestRepo, GitTestRepo)> { | 1618 | tokio::task::spawn_blocking(move || { |
| 1614 | // create 3 proposals | 1619 | // create 3 proposals |
| 1615 | let _ = cli_tester_create_proposals()?; | 1620 | let _ = cli_tester_create_proposals()?; |
| 1616 | // get proposal id of first | 1621 | // get proposal id of first |
| 1617 | let client = Client::new(&nostr::Keys::generate()); | 1622 | // get proposal id of first |
| 1618 | client.add_relay("ws://localhost:8055")?; | 1623 | let client = Client::default(); |
| 1619 | client.connect_relay("ws://localhost:8055")?; | 1624 | Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; |
| 1620 | let proposals = client.get_events_of( | 1625 | Handle::current() |
| 1626 | .block_on(client.connect_relay("ws://localhost:8055"))?; | ||
| 1627 | let proposals = Handle::current().block_on(client.get_events_of( | ||
| 1621 | vec![ | 1628 | vec![ |
| 1622 | nostr::Filter::default() | 1629 | nostr::Filter::default() |
| 1623 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 1630 | .kind(nostr::Kind::Custom(PATCH_KIND)) |
| 1624 | .custom_tag(nostr::Alphabet::T, vec!["root"]), | 1631 | .custom_tag( |
| 1625 | ], | 1632 | nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), |
| 1633 | vec!["root"], | ||
| 1634 | ), | ||
| 1635 | ], | ||
| 1626 | Some(Duration::from_millis(500)), | 1636 | Some(Duration::from_millis(500)), |
| 1627 | )?; | 1637 | ))?; |
| 1628 | client.disconnect()?; | 1638 | Handle::current().block_on(client.disconnect())?; |
| 1629 | 1639 | ||
| 1630 | let proposal_1_id = proposals | 1640 | let proposal_1_id = proposals |
| 1631 | .iter() | 1641 | .iter() |
| @@ -1699,8 +1709,7 @@ mod when_main_branch_is_uptodate { | |||
| 1699 | relay::shutdown_relay(8000 + p)?; | 1709 | relay::shutdown_relay(8000 + p)?; |
| 1700 | } | 1710 | } |
| 1701 | Ok((second_originating_repo, test_repo)) | 1711 | Ok((second_originating_repo, test_repo)) |
| 1702 | }, | 1712 | }); |
| 1703 | ); | ||
| 1704 | 1713 | ||
| 1705 | // launch relay | 1714 | // launch relay |
| 1706 | let _ = join!( | 1715 | let _ = join!( |
| @@ -1710,7 +1719,7 @@ mod when_main_branch_is_uptodate { | |||
| 1710 | r55.listen_until_close(), | 1719 | r55.listen_until_close(), |
| 1711 | r56.listen_until_close(), | 1720 | r56.listen_until_close(), |
| 1712 | ); | 1721 | ); |
| 1713 | let res = cli_tester_handle.join().unwrap()?; | 1722 | let res = cli_tester_handle.await??; |
| 1714 | 1723 | ||
| 1715 | Ok(res) | 1724 | Ok(res) |
| 1716 | } | 1725 | } |
| @@ -1737,96 +1746,105 @@ mod when_main_branch_is_uptodate { | |||
| 1737 | r55.events.push(generate_test_key_1_metadata_event("fred")); | 1746 | r55.events.push(generate_test_key_1_metadata_event("fred")); |
| 1738 | r55.events.push(generate_test_key_1_relay_list_event()); | 1747 | r55.events.push(generate_test_key_1_relay_list_event()); |
| 1739 | 1748 | ||
| 1740 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 1749 | let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking( |
| 1741 | // create 3 proposals | 1750 | move || { |
| 1742 | let _ = cli_tester_create_proposals()?; | 1751 | // create 3 proposals |
| 1743 | // get proposal id of first | 1752 | let _ = cli_tester_create_proposals()?; |
| 1744 | let client = Client::new(&nostr::Keys::generate()); | 1753 | // get proposal id of first |
| 1745 | client.add_relay("ws://localhost:8055")?; | 1754 | let client = Client::default(); |
| 1746 | client.connect_relay("ws://localhost:8055")?; | 1755 | Handle::current() |
| 1747 | let proposals = client.get_events_of( | 1756 | .block_on(client.add_relay("ws://localhost:8055"))?; |
| 1748 | vec![ | 1757 | Handle::current() |
| 1749 | nostr::Filter::default() | 1758 | .block_on(client.connect_relay("ws://localhost:8055"))?; |
| 1750 | .kind(nostr::Kind::Custom(PATCH_KIND)) | 1759 | let proposals = |
| 1751 | .custom_tag(nostr::Alphabet::T, vec!["root"]), | 1760 | Handle::current().block_on(client.get_events_of( |
| 1752 | ], | 1761 | vec![ |
| 1753 | Some(Duration::from_millis(500)), | 1762 | nostr::Filter::default() |
| 1754 | )?; | 1763 | .kind(nostr::Kind::Custom(PATCH_KIND)) |
| 1755 | client.disconnect()?; | 1764 | .custom_tag( |
| 1756 | 1765 | nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), | |
| 1757 | let proposal_1_id = proposals | 1766 | vec!["root"], |
| 1758 | .iter() | 1767 | ), |
| 1759 | .find(|e| { | 1768 | ], |
| 1760 | e.tags | 1769 | Some(Duration::from_millis(500)), |
| 1761 | .iter() | 1770 | ))?; |
| 1762 | .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1)) | 1771 | Handle::current().block_on(client.disconnect())?; |
| 1763 | }) | 1772 | |
| 1764 | .unwrap() | 1773 | let proposal_1_id = proposals |
| 1765 | .id; | 1774 | .iter() |
| 1766 | // recreate proposal 1 on top of a another commit (like a rebase on top | 1775 | .find(|e| { |
| 1767 | // of one extra commit) | 1776 | e.tags |
| 1768 | let second_originating_repo = GitTestRepo::default(); | 1777 | .iter() |
| 1769 | second_originating_repo.populate()?; | 1778 | .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1)) |
| 1770 | std::fs::write( | 1779 | }) |
| 1771 | second_originating_repo.dir.join("amazing.md"), | 1780 | .unwrap() |
| 1772 | "some content", | 1781 | .id; |
| 1773 | )?; | 1782 | // recreate proposal 1 on top of a another commit (like a rebase on |
| 1774 | second_originating_repo | 1783 | // top of one extra commit) |
| 1775 | .stage_and_commit("commit for rebasing on top of")?; | 1784 | let second_originating_repo = GitTestRepo::default(); |
| 1776 | cli_tester_create_proposal( | 1785 | second_originating_repo.populate()?; |
| 1777 | &second_originating_repo, | 1786 | std::fs::write( |
| 1778 | FEATURE_BRANCH_NAME_1, | 1787 | second_originating_repo.dir.join("amazing.md"), |
| 1779 | "a", | 1788 | "some content", |
| 1780 | Some((PROPOSAL_TITLE_1, "proposal a description")), | 1789 | )?; |
| 1781 | Some(proposal_1_id.to_string()), | 1790 | second_originating_repo |
| 1782 | )?; | 1791 | .stage_and_commit("commit for rebasing on top of")?; |
| 1783 | 1792 | cli_tester_create_proposal( | |
| 1784 | // pretend we have downloaded the origianl version of the first proposal | 1793 | &second_originating_repo, |
| 1785 | let test_repo = GitTestRepo::default(); | 1794 | FEATURE_BRANCH_NAME_1, |
| 1786 | test_repo.populate()?; | 1795 | "a", |
| 1787 | create_and_populate_branch( | 1796 | Some((PROPOSAL_TITLE_1, "proposal a description")), |
| 1788 | &test_repo, | 1797 | Some(proposal_1_id.to_string()), |
| 1789 | FEATURE_BRANCH_NAME_1, | 1798 | )?; |
| 1790 | "a", | 1799 | |
| 1791 | false, | 1800 | // pretend we have downloaded the origianl version of the first |
| 1792 | )?; | 1801 | // proposal |
| 1793 | // pretend we have pulled the updated main branch | 1802 | let test_repo = GitTestRepo::default(); |
| 1794 | test_repo.checkout("main")?; | 1803 | test_repo.populate()?; |
| 1795 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | 1804 | create_and_populate_branch( |
| 1796 | test_repo.stage_and_commit("commit for rebasing on top of")?; | 1805 | &test_repo, |
| 1797 | 1806 | FEATURE_BRANCH_NAME_1, | |
| 1798 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | 1807 | "a", |
| 1799 | p.expect("finding proposals...\r\n")?; | 1808 | false, |
| 1800 | let mut c = p.expect_choice( | 1809 | )?; |
| 1801 | "all proposals", | 1810 | // pretend we have pulled the updated main branch |
| 1802 | vec![ | 1811 | test_repo.checkout("main")?; |
| 1803 | format!("\"{PROPOSAL_TITLE_3}\""), | 1812 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; |
| 1804 | format!("\"{PROPOSAL_TITLE_2}\""), | 1813 | test_repo.stage_and_commit("commit for rebasing on top of")?; |
| 1805 | format!("\"{PROPOSAL_TITLE_1}\""), | 1814 | |
| 1806 | ], | 1815 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); |
| 1807 | )?; | 1816 | p.expect("finding proposals...\r\n")?; |
| 1808 | c.succeeds_with(2, true, None)?; | 1817 | let mut c = p.expect_choice( |
| 1809 | p.expect("finding commits...\r\n")?; | 1818 | "all proposals", |
| 1810 | p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; | 1819 | vec![ |
| 1811 | let mut c = p.expect_choice( | 1820 | format!("\"{PROPOSAL_TITLE_3}\""), |
| 1812 | "", | 1821 | format!("\"{PROPOSAL_TITLE_2}\""), |
| 1813 | vec![ | 1822 | format!("\"{PROPOSAL_TITLE_1}\""), |
| 1814 | format!("checkout and overwrite existing proposal branch"), | 1823 | ], |
| 1815 | format!("checkout existing outdated proposal branch"), | 1824 | )?; |
| 1816 | format!("apply to current branch with `git am`"), | 1825 | c.succeeds_with(2, true, None)?; |
| 1817 | format!("download to ./patches"), | 1826 | p.expect("finding commits...\r\n")?; |
| 1818 | format!("back"), | 1827 | p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; |
| 1819 | ], | 1828 | let mut c = p.expect_choice( |
| 1820 | )?; | 1829 | "", |
| 1821 | c.succeeds_with(0, false, Some(0))?; | 1830 | vec![ |
| 1822 | 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!("checkout and overwrite existing proposal branch"), |
| 1823 | p.expect_end()?; | 1832 | format!("checkout existing outdated proposal branch"), |
| 1824 | 1833 | format!("apply to current branch with `git am`"), | |
| 1825 | for p in [51, 52, 53, 55, 56] { | 1834 | format!("download to ./patches"), |
| 1826 | relay::shutdown_relay(8000 + p)?; | 1835 | format!("back"), |
| 1827 | } | 1836 | ], |
| 1828 | Ok(()) | 1837 | )?; |
| 1829 | }); | 1838 | c.succeeds_with(0, false, Some(0))?; |
| 1839 | p.expect("checked out new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; | ||
| 1840 | p.expect_end()?; | ||
| 1841 | |||
| 1842 | for p in [51, 52, 53, 55, 56] { | ||
| 1843 | relay::shutdown_relay(8000 + p)?; | ||
| 1844 | } | ||
| 1845 | Ok(()) | ||
| 1846 | }, | ||
| 1847 | ); | ||
| 1830 | 1848 | ||
| 1831 | // launch relay | 1849 | // launch relay |
| 1832 | let _ = join!( | 1850 | let _ = join!( |
| @@ -1836,7 +1854,7 @@ mod when_main_branch_is_uptodate { | |||
| 1836 | r55.listen_until_close(), | 1854 | r55.listen_until_close(), |
| 1837 | r56.listen_until_close(), | 1855 | r56.listen_until_close(), |
| 1838 | ); | 1856 | ); |
| 1839 | cli_tester_handle.join().unwrap()?; | 1857 | cli_tester_handle.await??; |
| 1840 | println!("{:?}", r55.events); | 1858 | println!("{:?}", r55.events); |
| 1841 | Ok(()) | 1859 | Ok(()) |
| 1842 | } | 1860 | } |