diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-09 08:35:53 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-09 08:40:47 +0100 |
| commit | 5618fd9883d45de1443a40abada944cbe3bb8dfd (patch) | |
| tree | 98588d4e8ff29d8b0c2ea26d9450f4567d05754b /tests | |
| parent | 2ccf599bf787d4cc0012209ead2d07bb0eb7ffca (diff) | |
feat(remote): `push` new proposal
issue new proposal when new branch is pushed into `prs/*` namespace,
which doesn't match an existing proposal
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/git_remote_helper.rs | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/tests/git_remote_helper.rs b/tests/git_remote_helper.rs index 7cf6799..17138e4 100644 --- a/tests/git_remote_helper.rs +++ b/tests/git_remote_helper.rs | |||
| @@ -2004,4 +2004,126 @@ mod push { | |||
| 2004 | 2004 | ||
| 2005 | Ok(()) | 2005 | Ok(()) |
| 2006 | } | 2006 | } |
| 2007 | |||
| 2008 | #[tokio::test] | ||
| 2009 | #[serial] | ||
| 2010 | async fn push_new_pr_branch_creates_proposal() -> Result<()> { | ||
| 2011 | let (events, source_git_repo) = prep_source_repo_and_events_including_proposals().await?; | ||
| 2012 | let source_path = source_git_repo.dir.to_str().unwrap().to_string(); | ||
| 2013 | |||
| 2014 | let (mut r51, mut r52, mut r53, mut r55, mut r56, mut r57) = ( | ||
| 2015 | Relay::new(8051, None, None), | ||
| 2016 | Relay::new(8052, None, None), | ||
| 2017 | Relay::new(8053, None, None), | ||
| 2018 | Relay::new(8055, None, None), | ||
| 2019 | Relay::new(8056, None, None), | ||
| 2020 | Relay::new(8057, None, None), | ||
| 2021 | ); | ||
| 2022 | r51.events = events.clone(); | ||
| 2023 | r55.events = events.clone(); | ||
| 2024 | |||
| 2025 | let before = r55.events.iter().cloned().collect::<HashSet<Event>>(); | ||
| 2026 | let branch_name = "prs/my-new-proposal"; | ||
| 2027 | |||
| 2028 | let cli_tester_handle = std::thread::spawn(move || -> Result<String> { | ||
| 2029 | let mut git_repo = clone_git_repo_with_nostr_url()?; | ||
| 2030 | git_repo.delete_dir_on_drop = false; | ||
| 2031 | git_repo.create_branch(branch_name)?; | ||
| 2032 | git_repo.checkout(branch_name)?; | ||
| 2033 | |||
| 2034 | std::fs::write(git_repo.dir.join("new.md"), "some content")?; | ||
| 2035 | git_repo.stage_and_commit("new.md")?; | ||
| 2036 | |||
| 2037 | std::fs::write(git_repo.dir.join("new2.md"), "some content")?; | ||
| 2038 | git_repo.stage_and_commit("new2.md")?; | ||
| 2039 | |||
| 2040 | let mut p = CliTester::new_git_with_remote_helper_from_dir( | ||
| 2041 | &git_repo.dir, | ||
| 2042 | ["push", "-u", "origin", branch_name], | ||
| 2043 | ); | ||
| 2044 | cli_expect_nostr_fetch(&mut p)?; | ||
| 2045 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | ||
| 2046 | p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; | ||
| 2047 | let output = p.expect_end_eventually()?; | ||
| 2048 | |||
| 2049 | for p in [51, 52, 53, 55, 56, 57] { | ||
| 2050 | relay::shutdown_relay(8000 + p)?; | ||
| 2051 | } | ||
| 2052 | |||
| 2053 | Ok(output) | ||
| 2054 | }); | ||
| 2055 | // launch relays | ||
| 2056 | let _ = join!( | ||
| 2057 | r51.listen_until_close(), | ||
| 2058 | r52.listen_until_close(), | ||
| 2059 | r53.listen_until_close(), | ||
| 2060 | r55.listen_until_close(), | ||
| 2061 | r56.listen_until_close(), | ||
| 2062 | r57.listen_until_close(), | ||
| 2063 | ); | ||
| 2064 | |||
| 2065 | let output = cli_tester_handle.join().unwrap()?; | ||
| 2066 | |||
| 2067 | assert_eq!( | ||
| 2068 | output, | ||
| 2069 | format!(" * [new branch] {branch_name} -> {branch_name}\r\nbranch '{branch_name}' set up to track 'origin/{branch_name}'.\r\n").as_str(), | ||
| 2070 | ); | ||
| 2071 | |||
| 2072 | let new_events = r55 | ||
| 2073 | .events | ||
| 2074 | .iter() | ||
| 2075 | .cloned() | ||
| 2076 | .collect::<HashSet<Event>>() | ||
| 2077 | .difference(&before) | ||
| 2078 | .cloned() | ||
| 2079 | .collect::<Vec<Event>>(); | ||
| 2080 | assert_eq!(new_events.len(), 2); | ||
| 2081 | |||
| 2082 | let proposal = new_events | ||
| 2083 | .iter() | ||
| 2084 | .find(|e| e.iter_tags().any(|t| t.as_vec()[1].eq("root"))) | ||
| 2085 | .unwrap(); | ||
| 2086 | |||
| 2087 | assert!( | ||
| 2088 | proposal.content.contains("new.md"), | ||
| 2089 | "first patch is proposal root" | ||
| 2090 | ); | ||
| 2091 | |||
| 2092 | assert!( | ||
| 2093 | proposal.content.contains("[PATCH 1/2]"), | ||
| 2094 | "proposal root labeled with[PATCH 1/2] event: {proposal:?}", | ||
| 2095 | ); | ||
| 2096 | |||
| 2097 | assert_eq!( | ||
| 2098 | proposal | ||
| 2099 | .iter_tags() | ||
| 2100 | .find(|t| t.as_vec()[0].eq("branch-name")) | ||
| 2101 | .unwrap() | ||
| 2102 | .as_vec()[1], | ||
| 2103 | branch_name.replace("prs/", ""), | ||
| 2104 | ); | ||
| 2105 | |||
| 2106 | let second_patch = new_events | ||
| 2107 | .iter() | ||
| 2108 | .find(|e| e.content.contains("new2.md")) | ||
| 2109 | .unwrap(); | ||
| 2110 | |||
| 2111 | assert!( | ||
| 2112 | second_patch.content.contains("[PATCH 2/2]"), | ||
| 2113 | "second patch labeled with [PATCH 2/2]" | ||
| 2114 | ); | ||
| 2115 | |||
| 2116 | assert_eq!( | ||
| 2117 | proposal.id().to_string(), | ||
| 2118 | second_patch | ||
| 2119 | .tags | ||
| 2120 | .iter() | ||
| 2121 | .find(|t| t.is_root()) | ||
| 2122 | .unwrap() | ||
| 2123 | .as_vec()[1], | ||
| 2124 | "second patch sets proposal id as root" | ||
| 2125 | ); | ||
| 2126 | |||
| 2127 | Ok(()) | ||
| 2128 | } | ||
| 2007 | } | 2129 | } |