diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-08-04 11:50:39 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-08-05 09:23:01 +0100 |
| commit | f48677bad3f3dabb80992806e0e4c8ad4d45c716 (patch) | |
| tree | 9d63debff0b602a15df56008cc739c087fbe8b26 /tests/ngit_send.rs | |
| parent | f76fe63da5f2c2f85215e86c8ecc63eda7c93902 (diff) | |
feat(send): support PR and PR update events
send as a PR if the commit would make patches that are too big for
nostr events.
send as a PR update if the proposal is PR.
send as a PR, revising a patch root, if patches would be too big.
in tests `get_pretend_proposal_root_event` has to be a actual proposal
with a tip, rather than just a cover letter, so we have replaced it.
Diffstat (limited to 'tests/ngit_send.rs')
| -rw-r--r-- | tests/ngit_send.rs | 84 |
1 files changed, 64 insertions, 20 deletions
diff --git a/tests/ngit_send.rs b/tests/ngit_send.rs index ec72667..e128bd9 100644 --- a/tests/ngit_send.rs +++ b/tests/ngit_send.rs | |||
| @@ -37,6 +37,25 @@ mod when_commits_behind_ask_to_proceed { | |||
| 37 | Ok(test_repo) | 37 | Ok(test_repo) |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | fn create_relay_51() -> Result<Relay<'static>> { | ||
| 41 | Ok(Relay::new( | ||
| 42 | 8051, | ||
| 43 | None, | ||
| 44 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 45 | relay.respond_events( | ||
| 46 | client_id, | ||
| 47 | &subscription_id, | ||
| 48 | &vec![ | ||
| 49 | generate_test_key_1_metadata_event("fred"), | ||
| 50 | generate_test_key_1_relay_list_event(), | ||
| 51 | generate_repo_ref_event(), | ||
| 52 | ], | ||
| 53 | )?; | ||
| 54 | Ok(()) | ||
| 55 | }), | ||
| 56 | )) | ||
| 57 | } | ||
| 58 | |||
| 40 | fn expect_confirm_prompt(p: &mut CliTester) -> Result<CliTesterConfirmPrompt> { | 59 | fn expect_confirm_prompt(p: &mut CliTester) -> Result<CliTesterConfirmPrompt> { |
| 41 | p.expect("fetching updates...\r\n")?; | 60 | p.expect("fetching updates...\r\n")?; |
| 42 | p.expect_eventually("\r\n")?; // may be 'no updates' or some updates | 61 | p.expect_eventually("\r\n")?; // may be 'no updates' or some updates |
| @@ -49,37 +68,62 @@ mod when_commits_behind_ask_to_proceed { | |||
| 49 | ) | 68 | ) |
| 50 | } | 69 | } |
| 51 | 70 | ||
| 52 | #[test] | 71 | #[tokio::test] |
| 53 | fn asked_with_default_no() -> Result<()> { | 72 | #[serial] |
| 73 | async fn asked_with_default_no() -> Result<()> { | ||
| 54 | let test_repo = prep_test_repo()?; | 74 | let test_repo = prep_test_repo()?; |
| 75 | let mut r51 = create_relay_51()?; | ||
| 76 | // // check relay had the right number of events | ||
| 77 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 78 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | ||
| 79 | expect_confirm_prompt(&mut p)?; | ||
| 80 | p.exit()?; | ||
| 81 | relay::shutdown_relay(8051)?; | ||
| 82 | Ok(()) | ||
| 83 | }); | ||
| 55 | 84 | ||
| 56 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | 85 | // launch relay |
| 57 | expect_confirm_prompt(&mut p)?; | 86 | r51.listen_until_close().await?; |
| 58 | p.exit()?; | 87 | cli_tester_handle.join().unwrap()?; |
| 59 | Ok(()) | 88 | Ok(()) |
| 60 | } | 89 | } |
| 61 | 90 | ||
| 62 | #[test] | 91 | #[tokio::test] |
| 63 | fn when_response_is_false_aborts() -> Result<()> { | 92 | #[serial] |
| 93 | async fn when_response_is_false_aborts() -> Result<()> { | ||
| 64 | let test_repo = prep_test_repo()?; | 94 | let test_repo = prep_test_repo()?; |
| 95 | let mut r51 = create_relay_51()?; | ||
| 96 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 97 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | ||
| 98 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(false))?; | ||
| 99 | p.expect_end_with("Error: aborting so commits can be rebased\r\n")?; | ||
| 100 | relay::shutdown_relay(8051)?; | ||
| 101 | Ok(()) | ||
| 102 | }); | ||
| 65 | 103 | ||
| 66 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | 104 | // launch relay |
| 67 | 105 | r51.listen_until_close().await?; | |
| 68 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(false))?; | 106 | cli_tester_handle.join().unwrap()?; |
| 69 | |||
| 70 | p.expect_end_with("Error: aborting so commits can be rebased\r\n")?; | ||
| 71 | |||
| 72 | Ok(()) | 107 | Ok(()) |
| 73 | } | 108 | } |
| 74 | #[test] | 109 | |
| 110 | #[tokio::test] | ||
| 75 | #[serial] | 111 | #[serial] |
| 76 | fn when_response_is_true_proceeds() -> Result<()> { | 112 | async fn when_response_is_true_proceeds() -> Result<()> { |
| 77 | let test_repo = prep_test_repo()?; | 113 | let test_repo = prep_test_repo()?; |
| 114 | let mut r51 = create_relay_51()?; | ||
| 115 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 116 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | ||
| 117 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(true))?; | ||
| 118 | p.expect("? include cover letter")?; | ||
| 119 | p.exit()?; | ||
| 120 | relay::shutdown_relay(8051)?; | ||
| 121 | Ok(()) | ||
| 122 | }); | ||
| 78 | 123 | ||
| 79 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | 124 | // launch relay |
| 80 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(true))?; | 125 | r51.listen_until_close().await?; |
| 81 | p.expect("? include cover letter")?; | 126 | cli_tester_handle.join().unwrap()?; |
| 82 | p.exit()?; | ||
| 83 | Ok(()) | 127 | Ok(()) |
| 84 | } | 128 | } |
| 85 | } | 129 | } |
| @@ -1620,7 +1664,7 @@ mod root_proposal_specified_using_in_reply_to_with_range_of_head_2_and_cover_let | |||
| 1620 | .unwrap() | 1664 | .unwrap() |
| 1621 | .as_slice()[1], | 1665 | .as_slice()[1], |
| 1622 | // id of state nevent | 1666 | // id of state nevent |
| 1623 | "431e58eb8e1b4e20292d1d5bbe81d5cfb042e1bc165de32eddfdd52245a4cce4", | 1667 | "000c104861e34a453481ab23e7de21a6baf475b394479705363b035936732528", |
| 1624 | ); | 1668 | ); |
| 1625 | } | 1669 | } |
| 1626 | Ok(()) | 1670 | Ok(()) |