diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-27 10:13:19 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-27 10:13:19 +0000 |
| commit | ef552c12a6604c4b834f80b68c342d7f9668aa4b (patch) | |
| tree | 2171eb4d26633a6220bf8d673bc4b58ccab3ab2b /tests | |
| parent | 72d1d0cb7539216add6e096309c15aa3c353539d (diff) | |
feat: remove `pull` `push` and `fetch` ngit cmds
to simplify the api and encourage use of the git remote helper
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ngit_pull.rs | 617 | ||||
| -rw-r--r-- | tests/ngit_push.rs | 531 |
2 files changed, 0 insertions, 1148 deletions
diff --git a/tests/ngit_pull.rs b/tests/ngit_pull.rs deleted file mode 100644 index 2fb9229..0000000 --- a/tests/ngit_pull.rs +++ /dev/null | |||
| @@ -1,617 +0,0 @@ | |||
| 1 | use anyhow::Result; | ||
| 2 | use futures::join; | ||
| 3 | use serial_test::serial; | ||
| 4 | use test_utils::{git::GitTestRepo, relay::Relay, *}; | ||
| 5 | |||
| 6 | mod when_main_is_checked_out { | ||
| 7 | use super::*; | ||
| 8 | |||
| 9 | mod cli_prompts { | ||
| 10 | use super::*; | ||
| 11 | |||
| 12 | #[tokio::test] | ||
| 13 | #[serial] | ||
| 14 | async fn cli_show_error() -> Result<()> { | ||
| 15 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 16 | Relay::new(8051, None, None), | ||
| 17 | Relay::new(8052, None, None), | ||
| 18 | Relay::new(8053, None, None), | ||
| 19 | Relay::new(8055, None, None), | ||
| 20 | Relay::new(8056, None, None), | ||
| 21 | ); | ||
| 22 | |||
| 23 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 24 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 25 | r51.events.push(generate_repo_ref_event()); | ||
| 26 | |||
| 27 | r55.events.push(generate_repo_ref_event()); | ||
| 28 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 29 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 30 | |||
| 31 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 32 | cli_tester_create_proposals()?; | ||
| 33 | |||
| 34 | let test_repo = create_repo_with_proposal_branch_pulled_and_checkedout(1)?; | ||
| 35 | |||
| 36 | test_repo.checkout("main")?; | ||
| 37 | |||
| 38 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 39 | p.expect("Error: checkout a branch associated with a proposal first\r\n")?; | ||
| 40 | p.expect_end()?; | ||
| 41 | |||
| 42 | for p in [51, 52, 53, 55, 56] { | ||
| 43 | relay::shutdown_relay(8000 + p)?; | ||
| 44 | } | ||
| 45 | Ok(()) | ||
| 46 | }); | ||
| 47 | |||
| 48 | // launch relay | ||
| 49 | let _ = join!( | ||
| 50 | r51.listen_until_close(), | ||
| 51 | r52.listen_until_close(), | ||
| 52 | r53.listen_until_close(), | ||
| 53 | r55.listen_until_close(), | ||
| 54 | r56.listen_until_close(), | ||
| 55 | ); | ||
| 56 | cli_tester_handle.join().unwrap()?; | ||
| 57 | Ok(()) | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | mod when_branch_doesnt_exist { | ||
| 63 | use super::*; | ||
| 64 | |||
| 65 | mod cli_prompts { | ||
| 66 | use super::*; | ||
| 67 | |||
| 68 | #[tokio::test] | ||
| 69 | #[serial] | ||
| 70 | async fn cli_show_error() -> Result<()> { | ||
| 71 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 72 | Relay::new(8051, None, None), | ||
| 73 | Relay::new(8052, None, None), | ||
| 74 | Relay::new(8053, None, None), | ||
| 75 | Relay::new(8055, None, None), | ||
| 76 | Relay::new(8056, None, None), | ||
| 77 | ); | ||
| 78 | |||
| 79 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 80 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 81 | r51.events.push(generate_repo_ref_event()); | ||
| 82 | |||
| 83 | r55.events.push(generate_repo_ref_event()); | ||
| 84 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 85 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 86 | |||
| 87 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 88 | cli_tester_create_proposals()?; | ||
| 89 | |||
| 90 | let test_repo = GitTestRepo::default(); | ||
| 91 | test_repo.populate()?; | ||
| 92 | |||
| 93 | test_repo.create_branch("random-name")?; | ||
| 94 | test_repo.checkout("random-name")?; | ||
| 95 | |||
| 96 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 97 | p.expect("fetching updates...\r\n")?; | ||
| 98 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 99 | p.expect( | ||
| 100 | "Error: failed to find proposal that matches the current branch name\r\n", | ||
| 101 | )?; | ||
| 102 | |||
| 103 | p.expect_end()?; | ||
| 104 | |||
| 105 | for p in [51, 52, 53, 55, 56] { | ||
| 106 | relay::shutdown_relay(8000 + p)?; | ||
| 107 | } | ||
| 108 | Ok(()) | ||
| 109 | }); | ||
| 110 | |||
| 111 | // launch relay | ||
| 112 | let _ = join!( | ||
| 113 | r51.listen_until_close(), | ||
| 114 | r52.listen_until_close(), | ||
| 115 | r53.listen_until_close(), | ||
| 116 | r55.listen_until_close(), | ||
| 117 | r56.listen_until_close(), | ||
| 118 | ); | ||
| 119 | cli_tester_handle.join().unwrap()?; | ||
| 120 | Ok(()) | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | mod when_branch_is_checked_out { | ||
| 126 | use super::*; | ||
| 127 | |||
| 128 | mod when_branch_is_up_to_date { | ||
| 129 | use super::*; | ||
| 130 | |||
| 131 | mod cli_prompts { | ||
| 132 | use super::*; | ||
| 133 | #[tokio::test] | ||
| 134 | #[serial] | ||
| 135 | async fn cli_show_up_to_date() -> Result<()> { | ||
| 136 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 137 | Relay::new(8051, None, None), | ||
| 138 | Relay::new(8052, None, None), | ||
| 139 | Relay::new(8053, None, None), | ||
| 140 | Relay::new(8055, None, None), | ||
| 141 | Relay::new(8056, None, None), | ||
| 142 | ); | ||
| 143 | |||
| 144 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 145 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 146 | r51.events.push(generate_repo_ref_event()); | ||
| 147 | |||
| 148 | r55.events.push(generate_repo_ref_event()); | ||
| 149 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 150 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 151 | |||
| 152 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 153 | let (_, test_repo) = | ||
| 154 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 155 | |||
| 156 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 157 | p.expect("fetching updates...\r\n")?; | ||
| 158 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 159 | p.expect("branch already up-to-date\r\n")?; | ||
| 160 | p.expect_end()?; | ||
| 161 | |||
| 162 | for p in [51, 52, 53, 55, 56] { | ||
| 163 | relay::shutdown_relay(8000 + p)?; | ||
| 164 | } | ||
| 165 | Ok(()) | ||
| 166 | }); | ||
| 167 | |||
| 168 | // launch relay | ||
| 169 | let _ = join!( | ||
| 170 | r51.listen_until_close(), | ||
| 171 | r52.listen_until_close(), | ||
| 172 | r53.listen_until_close(), | ||
| 173 | r55.listen_until_close(), | ||
| 174 | r56.listen_until_close(), | ||
| 175 | ); | ||
| 176 | cli_tester_handle.join().unwrap()?; | ||
| 177 | Ok(()) | ||
| 178 | } | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | mod when_branch_is_behind { | ||
| 183 | use super::*; | ||
| 184 | |||
| 185 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 186 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 187 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 188 | Relay::new(8051, None, None), | ||
| 189 | Relay::new(8052, None, None), | ||
| 190 | Relay::new(8053, None, None), | ||
| 191 | Relay::new(8055, None, None), | ||
| 192 | Relay::new(8056, None, None), | ||
| 193 | ); | ||
| 194 | |||
| 195 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 196 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 197 | r51.events.push(generate_repo_ref_event()); | ||
| 198 | |||
| 199 | r55.events.push(generate_repo_ref_event()); | ||
| 200 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 201 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 202 | |||
| 203 | let cli_tester_handle = | ||
| 204 | std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 205 | let (originating_repo, test_repo) = | ||
| 206 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 207 | |||
| 208 | let branch_name = | ||
| 209 | remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main( | ||
| 210 | &test_repo, | ||
| 211 | )?; | ||
| 212 | test_repo.checkout(&branch_name)?; | ||
| 213 | |||
| 214 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 215 | p.expect_end_eventually()?; | ||
| 216 | |||
| 217 | for p in [51, 52, 53, 55, 56] { | ||
| 218 | relay::shutdown_relay(8000 + p)?; | ||
| 219 | } | ||
| 220 | Ok((originating_repo, test_repo)) | ||
| 221 | }); | ||
| 222 | |||
| 223 | // launch relay | ||
| 224 | let _ = join!( | ||
| 225 | r51.listen_until_close(), | ||
| 226 | r52.listen_until_close(), | ||
| 227 | r53.listen_until_close(), | ||
| 228 | r55.listen_until_close(), | ||
| 229 | r56.listen_until_close(), | ||
| 230 | ); | ||
| 231 | let res = cli_tester_handle.join().unwrap()?; | ||
| 232 | |||
| 233 | Ok(res) | ||
| 234 | } | ||
| 235 | |||
| 236 | mod cli_prompts { | ||
| 237 | use super::*; | ||
| 238 | |||
| 239 | #[tokio::test] | ||
| 240 | #[serial] | ||
| 241 | async fn cli_applied_1_commit() -> Result<()> { | ||
| 242 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 243 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 244 | Relay::new(8051, None, None), | ||
| 245 | Relay::new(8052, None, None), | ||
| 246 | Relay::new(8053, None, None), | ||
| 247 | Relay::new(8055, None, None), | ||
| 248 | Relay::new(8056, None, None), | ||
| 249 | ); | ||
| 250 | |||
| 251 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 252 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 253 | r51.events.push(generate_repo_ref_event()); | ||
| 254 | |||
| 255 | r55.events.push(generate_repo_ref_event()); | ||
| 256 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 257 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 258 | |||
| 259 | let cli_tester_handle = | ||
| 260 | std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 261 | let (originating_repo, test_repo) = | ||
| 262 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 263 | |||
| 264 | let branch_name = | ||
| 265 | remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main( | ||
| 266 | &test_repo, | ||
| 267 | )?; | ||
| 268 | test_repo.checkout(&branch_name)?; | ||
| 269 | |||
| 270 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 271 | p.expect("fetching updates...\r\n")?; | ||
| 272 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 273 | p.expect_end_with("applied 1 new commits\r\n")?; | ||
| 274 | |||
| 275 | for p in [51, 52, 53, 55, 56] { | ||
| 276 | relay::shutdown_relay(8000 + p)?; | ||
| 277 | } | ||
| 278 | Ok((originating_repo, test_repo)) | ||
| 279 | }); | ||
| 280 | |||
| 281 | // launch relay | ||
| 282 | let _ = join!( | ||
| 283 | r51.listen_until_close(), | ||
| 284 | r52.listen_until_close(), | ||
| 285 | r53.listen_until_close(), | ||
| 286 | r55.listen_until_close(), | ||
| 287 | r56.listen_until_close(), | ||
| 288 | ); | ||
| 289 | cli_tester_handle.join().unwrap()?; | ||
| 290 | |||
| 291 | Ok(()) | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
| 295 | #[tokio::test] | ||
| 296 | #[serial] | ||
| 297 | async fn proposal_branch_tip_is_most_recent_patch() -> Result<()> { | ||
| 298 | let (originating_repo, test_repo) = prep_and_run().await?; | ||
| 299 | assert_eq!( | ||
| 300 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 301 | test_repo.get_tip_of_local_branch(&get_proposal_branch_name( | ||
| 302 | &test_repo, | ||
| 303 | FEATURE_BRANCH_NAME_1 | ||
| 304 | )?)?, | ||
| 305 | ); | ||
| 306 | Ok(()) | ||
| 307 | } | ||
| 308 | } | ||
| 309 | |||
| 310 | mod when_latest_proposal_amended_locally { | ||
| 311 | use super::*; | ||
| 312 | |||
| 313 | mod cli_prompts { | ||
| 314 | use super::*; | ||
| 315 | |||
| 316 | #[tokio::test] | ||
| 317 | #[serial] | ||
| 318 | async fn cli_output_correct() -> Result<()> { | ||
| 319 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 320 | Relay::new(8051, None, None), | ||
| 321 | Relay::new(8052, None, None), | ||
| 322 | Relay::new(8053, None, None), | ||
| 323 | Relay::new(8055, None, None), | ||
| 324 | Relay::new(8056, None, None), | ||
| 325 | ); | ||
| 326 | |||
| 327 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 328 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 329 | r51.events.push(generate_repo_ref_event()); | ||
| 330 | |||
| 331 | r55.events.push(generate_repo_ref_event()); | ||
| 332 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 333 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 334 | |||
| 335 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 336 | let (_, test_repo) = | ||
| 337 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 338 | |||
| 339 | amend_last_commit(&test_repo, "add ammended-commit.md")?; | ||
| 340 | |||
| 341 | // run test | ||
| 342 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 343 | p.expect("fetching updates...\r\n")?; | ||
| 344 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 345 | p.expect( | ||
| 346 | "you have an amended/rebase version the proposal that is unpublished\r\n", | ||
| 347 | )?; | ||
| 348 | p.expect("you have previously applied the latest version of the proposal (2 ahead 0 behind 'main') but your local proposal branch has amended or rebased it (2 ahead 0 behind 'main')\r\n")?; | ||
| 349 | p.expect("to view the latest proposal but retain your changes:\r\n")?; | ||
| 350 | p.expect(" 1) create a new branch off the tip commit of this one to store your changes\r\n")?; | ||
| 351 | p.expect(" 2) run `ngit list` and checkout the latest published version of this proposal\r\n")?; | ||
| 352 | p.expect("if you are confident in your changes consider running `ngit push --force`\r\n")?; | ||
| 353 | p.expect_end()?; | ||
| 354 | |||
| 355 | for p in [51, 52, 53, 55, 56] { | ||
| 356 | relay::shutdown_relay(8000 + p)?; | ||
| 357 | } | ||
| 358 | Ok(()) | ||
| 359 | }); | ||
| 360 | |||
| 361 | // launch relay | ||
| 362 | let _ = join!( | ||
| 363 | r51.listen_until_close(), | ||
| 364 | r52.listen_until_close(), | ||
| 365 | r53.listen_until_close(), | ||
| 366 | r55.listen_until_close(), | ||
| 367 | r56.listen_until_close(), | ||
| 368 | ); | ||
| 369 | cli_tester_handle.join().unwrap()?; | ||
| 370 | println!("{:?}", r55.events); | ||
| 371 | Ok(()) | ||
| 372 | } | ||
| 373 | } | ||
| 374 | } | ||
| 375 | |||
| 376 | mod when_local_commits_on_uptodate_proposal { | ||
| 377 | use super::*; | ||
| 378 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 379 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 380 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 381 | Relay::new(8051, None, None), | ||
| 382 | Relay::new(8052, None, None), | ||
| 383 | Relay::new(8053, None, None), | ||
| 384 | Relay::new(8055, None, None), | ||
| 385 | Relay::new(8056, None, None), | ||
| 386 | ); | ||
| 387 | |||
| 388 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 389 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 390 | r51.events.push(generate_repo_ref_event()); | ||
| 391 | |||
| 392 | r55.events.push(generate_repo_ref_event()); | ||
| 393 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 394 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 395 | |||
| 396 | let cli_tester_handle = std::thread::spawn( | ||
| 397 | move || -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 398 | let (originating_repo, test_repo) = | ||
| 399 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 400 | |||
| 401 | // add another commit (so we have a local branch 1 ahead) | ||
| 402 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; | ||
| 403 | test_repo.stage_and_commit("add ammended-commit.md")?; | ||
| 404 | |||
| 405 | // run test | ||
| 406 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 407 | p.expect("fetching updates...\r\n")?; | ||
| 408 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 409 | p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?; | ||
| 410 | p.expect_end()?; | ||
| 411 | |||
| 412 | for p in [51, 52, 53, 55, 56] { | ||
| 413 | relay::shutdown_relay(8000 + p)?; | ||
| 414 | } | ||
| 415 | Ok((originating_repo, test_repo)) | ||
| 416 | }, | ||
| 417 | ); | ||
| 418 | |||
| 419 | // launch relay | ||
| 420 | let _ = join!( | ||
| 421 | r51.listen_until_close(), | ||
| 422 | r52.listen_until_close(), | ||
| 423 | r53.listen_until_close(), | ||
| 424 | r55.listen_until_close(), | ||
| 425 | r56.listen_until_close(), | ||
| 426 | ); | ||
| 427 | let res = cli_tester_handle.join().unwrap()?; | ||
| 428 | |||
| 429 | Ok(res) | ||
| 430 | } | ||
| 431 | |||
| 432 | mod cli_prompts { | ||
| 433 | use super::*; | ||
| 434 | |||
| 435 | #[tokio::test] | ||
| 436 | #[serial] | ||
| 437 | async fn prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 438 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 439 | Relay::new(8051, None, None), | ||
| 440 | Relay::new(8052, None, None), | ||
| 441 | Relay::new(8053, None, None), | ||
| 442 | Relay::new(8055, None, None), | ||
| 443 | Relay::new(8056, None, None), | ||
| 444 | ); | ||
| 445 | |||
| 446 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 447 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 448 | r51.events.push(generate_repo_ref_event()); | ||
| 449 | |||
| 450 | r55.events.push(generate_repo_ref_event()); | ||
| 451 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 452 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 453 | |||
| 454 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 455 | let (_, test_repo) = | ||
| 456 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 457 | |||
| 458 | // add another commit (so we have a local branch 1 ahead) | ||
| 459 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; | ||
| 460 | test_repo.stage_and_commit("add ammended-commit.md")?; | ||
| 461 | |||
| 462 | // run test | ||
| 463 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 464 | p.expect("fetching updates...\r\n")?; | ||
| 465 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 466 | p.expect("local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal\r\n")?; | ||
| 467 | p.expect_end()?; | ||
| 468 | |||
| 469 | for p in [51, 52, 53, 55, 56] { | ||
| 470 | relay::shutdown_relay(8000 + p)?; | ||
| 471 | } | ||
| 472 | Ok(()) | ||
| 473 | }); | ||
| 474 | |||
| 475 | // launch relay | ||
| 476 | let _ = join!( | ||
| 477 | r51.listen_until_close(), | ||
| 478 | r52.listen_until_close(), | ||
| 479 | r53.listen_until_close(), | ||
| 480 | r55.listen_until_close(), | ||
| 481 | r56.listen_until_close(), | ||
| 482 | ); | ||
| 483 | cli_tester_handle.join().unwrap()?; | ||
| 484 | println!("{:?}", r55.events); | ||
| 485 | Ok(()) | ||
| 486 | } | ||
| 487 | } | ||
| 488 | |||
| 489 | #[tokio::test] | ||
| 490 | #[serial] | ||
| 491 | async fn didnt_overwrite_local_appendments() -> Result<()> { | ||
| 492 | let (originating_repo, test_repo) = prep_and_run().await?; | ||
| 493 | assert_ne!( | ||
| 494 | test_repo.get_tip_of_local_branch(&get_proposal_branch_name( | ||
| 495 | &test_repo, | ||
| 496 | FEATURE_BRANCH_NAME_1 | ||
| 497 | )?)?, | ||
| 498 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 499 | ); | ||
| 500 | Ok(()) | ||
| 501 | } | ||
| 502 | } | ||
| 503 | mod when_latest_event_rebases_branch { | ||
| 504 | use tokio::task::JoinHandle; | ||
| 505 | |||
| 506 | use super::*; | ||
| 507 | |||
| 508 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 509 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 510 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 511 | Relay::new(8051, None, None), | ||
| 512 | Relay::new(8052, None, None), | ||
| 513 | Relay::new(8053, None, None), | ||
| 514 | Relay::new(8055, None, None), | ||
| 515 | Relay::new(8056, None, None), | ||
| 516 | ); | ||
| 517 | |||
| 518 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 519 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 520 | r51.events.push(generate_repo_ref_event()); | ||
| 521 | |||
| 522 | r55.events.push(generate_repo_ref_event()); | ||
| 523 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 524 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 525 | |||
| 526 | let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> = | ||
| 527 | tokio::task::spawn_blocking(move || { | ||
| 528 | let (originating_repo, test_repo) = create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebased_proposal()?; | ||
| 529 | |||
| 530 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 531 | p.expect_end_eventually_and_print()?; | ||
| 532 | |||
| 533 | for p in [51, 52, 53, 55, 56] { | ||
| 534 | relay::shutdown_relay(8000 + p)?; | ||
| 535 | } | ||
| 536 | Ok((originating_repo, test_repo)) | ||
| 537 | }); | ||
| 538 | |||
| 539 | // launch relay | ||
| 540 | let _ = join!( | ||
| 541 | r51.listen_until_close(), | ||
| 542 | r52.listen_until_close(), | ||
| 543 | r53.listen_until_close(), | ||
| 544 | r55.listen_until_close(), | ||
| 545 | r56.listen_until_close(), | ||
| 546 | ); | ||
| 547 | let res = cli_tester_handle.await??; | ||
| 548 | |||
| 549 | Ok(res) | ||
| 550 | } | ||
| 551 | |||
| 552 | mod cli_prompts { | ||
| 553 | use super::*; | ||
| 554 | |||
| 555 | #[tokio::test] | ||
| 556 | #[serial] | ||
| 557 | async fn prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 558 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 559 | Relay::new(8051, None, None), | ||
| 560 | Relay::new(8052, None, None), | ||
| 561 | Relay::new(8053, None, None), | ||
| 562 | Relay::new(8055, None, None), | ||
| 563 | Relay::new(8056, None, None), | ||
| 564 | ); | ||
| 565 | |||
| 566 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 567 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 568 | r51.events.push(generate_repo_ref_event()); | ||
| 569 | |||
| 570 | r55.events.push(generate_repo_ref_event()); | ||
| 571 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 572 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 573 | |||
| 574 | let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking( | ||
| 575 | move || { | ||
| 576 | let (_, test_repo) = create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebased_proposal()?; | ||
| 577 | |||
| 578 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 579 | p.expect("fetching updates...\r\n")?; | ||
| 580 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 581 | p.expect_end_with("pulled new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; | ||
| 582 | for p in [51, 52, 53, 55, 56] { | ||
| 583 | relay::shutdown_relay(8000 + p)?; | ||
| 584 | } | ||
| 585 | Ok(()) | ||
| 586 | }, | ||
| 587 | ); | ||
| 588 | |||
| 589 | // launch relay | ||
| 590 | let _ = join!( | ||
| 591 | r51.listen_until_close(), | ||
| 592 | r52.listen_until_close(), | ||
| 593 | r53.listen_until_close(), | ||
| 594 | r55.listen_until_close(), | ||
| 595 | r56.listen_until_close(), | ||
| 596 | ); | ||
| 597 | cli_tester_handle.await??; | ||
| 598 | println!("{:?}", r55.events); | ||
| 599 | Ok(()) | ||
| 600 | } | ||
| 601 | } | ||
| 602 | |||
| 603 | #[tokio::test] | ||
| 604 | #[serial] | ||
| 605 | async fn proposal_branch_tip_is_most_recent_proposal_revision_tip() -> Result<()> { | ||
| 606 | let (originating_repo, test_repo) = prep_and_run().await?; | ||
| 607 | assert_eq!( | ||
| 608 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 609 | test_repo.get_tip_of_local_branch(&get_proposal_branch_name( | ||
| 610 | &test_repo, | ||
| 611 | FEATURE_BRANCH_NAME_1 | ||
| 612 | )?)?, | ||
| 613 | ); | ||
| 614 | Ok(()) | ||
| 615 | } | ||
| 616 | } | ||
| 617 | } | ||
diff --git a/tests/ngit_push.rs b/tests/ngit_push.rs deleted file mode 100644 index d4b3894..0000000 --- a/tests/ngit_push.rs +++ /dev/null | |||
| @@ -1,531 +0,0 @@ | |||
| 1 | use anyhow::Result; | ||
| 2 | use futures::join; | ||
| 3 | use serial_test::serial; | ||
| 4 | use test_utils::{git::GitTestRepo, relay::Relay, *}; | ||
| 5 | |||
| 6 | mod when_main_is_checked_out { | ||
| 7 | use super::*; | ||
| 8 | |||
| 9 | #[test] | ||
| 10 | fn cli_returns_error() -> Result<()> { | ||
| 11 | let test_repo = GitTestRepo::default(); | ||
| 12 | test_repo.populate()?; | ||
| 13 | create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; | ||
| 14 | test_repo.checkout("main")?; | ||
| 15 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); | ||
| 16 | p.expect("Error: checkout a branch associated with a proposal first\r\n")?; | ||
| 17 | p.expect_end()?; | ||
| 18 | Ok(()) | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | mod when_proposal_isnt_associated_with_branch_name { | ||
| 23 | use super::*; | ||
| 24 | |||
| 25 | mod cli_prompts { | ||
| 26 | |||
| 27 | use super::*; | ||
| 28 | |||
| 29 | #[tokio::test] | ||
| 30 | #[serial] | ||
| 31 | async fn cli_show_error() -> Result<()> { | ||
| 32 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 33 | Relay::new(8051, None, None), | ||
| 34 | Relay::new(8052, None, None), | ||
| 35 | Relay::new(8053, None, None), | ||
| 36 | Relay::new(8055, None, None), | ||
| 37 | Relay::new(8056, None, None), | ||
| 38 | ); | ||
| 39 | |||
| 40 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 41 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 42 | r51.events.push(generate_repo_ref_event()); | ||
| 43 | |||
| 44 | r55.events.push(generate_repo_ref_event()); | ||
| 45 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 46 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 47 | |||
| 48 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 49 | cli_tester_create_proposals()?; | ||
| 50 | |||
| 51 | let test_repo = GitTestRepo::default(); | ||
| 52 | test_repo.populate()?; | ||
| 53 | |||
| 54 | test_repo.create_branch("random-name")?; | ||
| 55 | test_repo.checkout("random-name")?; | ||
| 56 | |||
| 57 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); | ||
| 58 | p.expect("fetching updates...\r\n")?; | ||
| 59 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 60 | p.expect_end_with( | ||
| 61 | "Error: failed to find proposal that matches the current branch name\r\n", | ||
| 62 | )?; | ||
| 63 | for p in [51, 52, 53, 55, 56] { | ||
| 64 | relay::shutdown_relay(8000 + p)?; | ||
| 65 | } | ||
| 66 | Ok(()) | ||
| 67 | }); | ||
| 68 | |||
| 69 | // launch relay | ||
| 70 | let _ = join!( | ||
| 71 | r51.listen_until_close(), | ||
| 72 | r52.listen_until_close(), | ||
| 73 | r53.listen_until_close(), | ||
| 74 | r55.listen_until_close(), | ||
| 75 | r56.listen_until_close(), | ||
| 76 | ); | ||
| 77 | cli_tester_handle.join().unwrap()?; | ||
| 78 | Ok(()) | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | mod when_branch_is_checked_out { | ||
| 84 | use super::*; | ||
| 85 | |||
| 86 | mod when_branch_is_up_to_date { | ||
| 87 | use super::*; | ||
| 88 | |||
| 89 | mod cli_prompts { | ||
| 90 | use super::*; | ||
| 91 | #[tokio::test] | ||
| 92 | #[serial] | ||
| 93 | async fn cli_show_up_to_date() -> Result<()> { | ||
| 94 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 95 | Relay::new(8051, None, None), | ||
| 96 | Relay::new(8052, None, None), | ||
| 97 | Relay::new(8053, None, None), | ||
| 98 | Relay::new(8055, None, None), | ||
| 99 | Relay::new(8056, None, None), | ||
| 100 | ); | ||
| 101 | |||
| 102 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 103 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 104 | r51.events.push(generate_repo_ref_event()); | ||
| 105 | |||
| 106 | r55.events.push(generate_repo_ref_event()); | ||
| 107 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 108 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 109 | |||
| 110 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 111 | let (_, test_repo) = | ||
| 112 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 113 | |||
| 114 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); | ||
| 115 | p.expect("fetching updates...\r\n")?; | ||
| 116 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 117 | p.expect_end_with("Error: proposal already up-to-date with local branch\r\n")?; | ||
| 118 | |||
| 119 | for p in [51, 52, 53, 55, 56] { | ||
| 120 | relay::shutdown_relay(8000 + p)?; | ||
| 121 | } | ||
| 122 | Ok(()) | ||
| 123 | }); | ||
| 124 | |||
| 125 | // launch relay | ||
| 126 | let _ = join!( | ||
| 127 | r51.listen_until_close(), | ||
| 128 | r52.listen_until_close(), | ||
| 129 | r53.listen_until_close(), | ||
| 130 | r55.listen_until_close(), | ||
| 131 | r56.listen_until_close(), | ||
| 132 | ); | ||
| 133 | cli_tester_handle.join().unwrap()?; | ||
| 134 | Ok(()) | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | mod when_branch_is_behind { | ||
| 140 | use super::*; | ||
| 141 | |||
| 142 | mod cli_prompts { | ||
| 143 | use super::*; | ||
| 144 | |||
| 145 | #[tokio::test] | ||
| 146 | #[serial] | ||
| 147 | async fn cli_show_proposal_ahead_error() -> Result<()> { | ||
| 148 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 149 | Relay::new(8051, None, None), | ||
| 150 | Relay::new(8052, None, None), | ||
| 151 | Relay::new(8053, None, None), | ||
| 152 | Relay::new(8055, None, None), | ||
| 153 | Relay::new(8056, None, None), | ||
| 154 | ); | ||
| 155 | |||
| 156 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 157 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 158 | r51.events.push(generate_repo_ref_event()); | ||
| 159 | |||
| 160 | r55.events.push(generate_repo_ref_event()); | ||
| 161 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 162 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 163 | |||
| 164 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 165 | let (_, test_repo) = | ||
| 166 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 167 | |||
| 168 | let branch_name = | ||
| 169 | remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main( | ||
| 170 | &test_repo, | ||
| 171 | )?; | ||
| 172 | |||
| 173 | test_repo.checkout(&branch_name)?; | ||
| 174 | // run test | ||
| 175 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); | ||
| 176 | p.expect("fetching updates...\r\n")?; | ||
| 177 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 178 | p.expect("Error: proposal is ahead of local branch\r\n")?; | ||
| 179 | p.expect_end()?; | ||
| 180 | |||
| 181 | for p in [51, 52, 53, 55, 56] { | ||
| 182 | relay::shutdown_relay(8000 + p)?; | ||
| 183 | } | ||
| 184 | Ok(()) | ||
| 185 | }); | ||
| 186 | |||
| 187 | // launch relay | ||
| 188 | let _ = join!( | ||
| 189 | r51.listen_until_close(), | ||
| 190 | r52.listen_until_close(), | ||
| 191 | r53.listen_until_close(), | ||
| 192 | r55.listen_until_close(), | ||
| 193 | r56.listen_until_close(), | ||
| 194 | ); | ||
| 195 | cli_tester_handle.join().unwrap()?; | ||
| 196 | Ok(()) | ||
| 197 | } | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | mod when_branch_is_ahead { | ||
| 202 | use super::*; | ||
| 203 | |||
| 204 | mod cli_prompts { | ||
| 205 | use test_utils::relay::expect_send_with_progress; | ||
| 206 | |||
| 207 | use super::*; | ||
| 208 | |||
| 209 | #[tokio::test] | ||
| 210 | #[serial] | ||
| 211 | async fn cli_applied_1_commit() -> Result<()> { | ||
| 212 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 213 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 214 | Relay::new(8051, None, None), | ||
| 215 | Relay::new(8052, None, None), | ||
| 216 | Relay::new(8053, None, None), | ||
| 217 | Relay::new(8055, None, None), | ||
| 218 | Relay::new(8056, None, None), | ||
| 219 | ); | ||
| 220 | |||
| 221 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 222 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 223 | r51.events.push(generate_repo_ref_event()); | ||
| 224 | |||
| 225 | r55.events.push(generate_repo_ref_event()); | ||
| 226 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 227 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 228 | |||
| 229 | let cli_tester_handle = | ||
| 230 | std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 231 | let (originating_repo, test_repo) = | ||
| 232 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 233 | |||
| 234 | // add another commit (so we have an ammened local branch) | ||
| 235 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; | ||
| 236 | test_repo.stage_and_commit("add ammended-commit.md")?; | ||
| 237 | |||
| 238 | // run test | ||
| 239 | let mut p = CliTester::new_from_dir( | ||
| 240 | &test_repo.dir, | ||
| 241 | [ | ||
| 242 | "--nsec", | ||
| 243 | TEST_KEY_1_NSEC, | ||
| 244 | "--password", | ||
| 245 | TEST_PASSWORD, | ||
| 246 | "--disable-cli-spinners", | ||
| 247 | "push", | ||
| 248 | ], | ||
| 249 | ); | ||
| 250 | p.expect("fetching updates...\r\n")?; | ||
| 251 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 252 | p.expect( | ||
| 253 | "1 commits ahead. preparing to create creating patch events.\r\n", | ||
| 254 | )?; | ||
| 255 | p.expect("logged in as fred via cli arguments\r\n")?; | ||
| 256 | p.expect("pushing 1 commits\r\n")?; | ||
| 257 | |||
| 258 | expect_send_with_progress( | ||
| 259 | &mut p, | ||
| 260 | vec![ | ||
| 261 | (" [my-relay] [repo-relay] ws://localhost:8055", true, ""), | ||
| 262 | (" [my-relay] ws://localhost:8053", true, ""), | ||
| 263 | (" [repo-relay] ws://localhost:8056", true, ""), | ||
| 264 | (" [default] ws://localhost:8051", true, ""), | ||
| 265 | (" [default] ws://localhost:8052", true, ""), | ||
| 266 | ], | ||
| 267 | 1, | ||
| 268 | )?; | ||
| 269 | p.expect_eventually("pushed 1 commits\r\n")?; | ||
| 270 | p.expect_end()?; | ||
| 271 | |||
| 272 | for p in [51, 52, 53, 55, 56] { | ||
| 273 | relay::shutdown_relay(8000 + p)?; | ||
| 274 | } | ||
| 275 | Ok((originating_repo, test_repo)) | ||
| 276 | }); | ||
| 277 | |||
| 278 | // launch relay | ||
| 279 | let _ = join!( | ||
| 280 | r51.listen_until_close(), | ||
| 281 | r52.listen_until_close(), | ||
| 282 | r53.listen_until_close(), | ||
| 283 | r55.listen_until_close(), | ||
| 284 | r56.listen_until_close(), | ||
| 285 | ); | ||
| 286 | cli_tester_handle.join().unwrap()?; | ||
| 287 | |||
| 288 | Ok(()) | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | async fn prep_and_run() -> Result<(GitTestRepo, Vec<nostr::Event>)> { | ||
| 293 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 294 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 295 | Relay::new(8051, None, None), | ||
| 296 | Relay::new(8052, None, None), | ||
| 297 | Relay::new(8053, None, None), | ||
| 298 | Relay::new(8055, None, None), | ||
| 299 | Relay::new(8056, None, None), | ||
| 300 | ); | ||
| 301 | |||
| 302 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 303 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 304 | r51.events.push(generate_repo_ref_event()); | ||
| 305 | |||
| 306 | r55.events.push(generate_repo_ref_event()); | ||
| 307 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 308 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 309 | |||
| 310 | let cli_tester_handle = std::thread::spawn(move || -> Result<GitTestRepo> { | ||
| 311 | let (_, test_repo) = | ||
| 312 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 313 | |||
| 314 | // add another commit (so we have an ammened local branch) | ||
| 315 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; | ||
| 316 | test_repo.stage_and_commit("add ammended-commit.md")?; | ||
| 317 | |||
| 318 | // run test | ||
| 319 | |||
| 320 | let mut p = CliTester::new_from_dir( | ||
| 321 | &test_repo.dir, | ||
| 322 | [ | ||
| 323 | "--nsec", | ||
| 324 | TEST_KEY_1_NSEC, | ||
| 325 | "--password", | ||
| 326 | TEST_PASSWORD, | ||
| 327 | "--disable-cli-spinners", | ||
| 328 | "push", | ||
| 329 | ], | ||
| 330 | ); | ||
| 331 | p.expect_end_eventually()?; | ||
| 332 | |||
| 333 | for p in [51, 52, 53, 55, 56] { | ||
| 334 | relay::shutdown_relay(8000 + p)?; | ||
| 335 | } | ||
| 336 | Ok(test_repo) | ||
| 337 | }); | ||
| 338 | |||
| 339 | // launch relay | ||
| 340 | let _ = join!( | ||
| 341 | r51.listen_until_close(), | ||
| 342 | r52.listen_until_close(), | ||
| 343 | r53.listen_until_close(), | ||
| 344 | r55.listen_until_close(), | ||
| 345 | r56.listen_until_close(), | ||
| 346 | ); | ||
| 347 | let res = cli_tester_handle.join().unwrap()?; | ||
| 348 | |||
| 349 | Ok((res, r55.events.clone())) | ||
| 350 | } | ||
| 351 | #[tokio::test] | ||
| 352 | #[serial] | ||
| 353 | async fn commits_issued_as_patch_event() -> Result<()> { | ||
| 354 | let (test_repo, r55_events) = prep_and_run().await?; | ||
| 355 | |||
| 356 | let commit_id = test_repo | ||
| 357 | .get_tip_of_local_branch(&test_repo.get_checked_out_branch_name()?)? | ||
| 358 | .to_string(); | ||
| 359 | assert!(r55_events.iter().any(|e| { | ||
| 360 | e.tags | ||
| 361 | .iter() | ||
| 362 | .any(|t| t.as_slice()[0].eq("commit") && t.as_slice()[1].eq(&commit_id)) | ||
| 363 | })); | ||
| 364 | Ok(()) | ||
| 365 | } | ||
| 366 | } | ||
| 367 | |||
| 368 | mod when_branch_has_been_rebased { | ||
| 369 | use super::*; | ||
| 370 | |||
| 371 | mod cli_prompts { | ||
| 372 | use super::*; | ||
| 373 | |||
| 374 | #[tokio::test] | ||
| 375 | #[serial] | ||
| 376 | async fn cli_shows_unpublished_rebase_error() -> Result<()> { | ||
| 377 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 378 | Relay::new(8051, None, None), | ||
| 379 | Relay::new(8052, None, None), | ||
| 380 | Relay::new(8053, None, None), | ||
| 381 | Relay::new(8055, None, None), | ||
| 382 | Relay::new(8056, None, None), | ||
| 383 | ); | ||
| 384 | |||
| 385 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 386 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 387 | r51.events.push(generate_repo_ref_event()); | ||
| 388 | |||
| 389 | r55.events.push(generate_repo_ref_event()); | ||
| 390 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 391 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 392 | |||
| 393 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 394 | let (_, tmp_repo) = | ||
| 395 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 396 | let branch_name = tmp_repo.get_checked_out_branch_name()?; | ||
| 397 | |||
| 398 | let test_repo = GitTestRepo::default(); | ||
| 399 | test_repo.populate()?; | ||
| 400 | |||
| 401 | // simulate rebase | ||
| 402 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | ||
| 403 | test_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 404 | create_and_populate_branch(&test_repo, &branch_name, "a", true)?; | ||
| 405 | |||
| 406 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); | ||
| 407 | // p.expect_end_eventually_and_print()?; | ||
| 408 | |||
| 409 | p.expect("fetching updates...\r\n")?; | ||
| 410 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 411 | p.expect( | ||
| 412 | "Error: local unpublished proposal has been rebased. consider force pushing\r\n", | ||
| 413 | )?; | ||
| 414 | p.expect_end()?; | ||
| 415 | |||
| 416 | for p in [51, 52, 53, 55, 56] { | ||
| 417 | relay::shutdown_relay(8000 + p)?; | ||
| 418 | } | ||
| 419 | Ok(()) | ||
| 420 | }); | ||
| 421 | |||
| 422 | // launch relay | ||
| 423 | let _ = join!( | ||
| 424 | r51.listen_until_close(), | ||
| 425 | r52.listen_until_close(), | ||
| 426 | r53.listen_until_close(), | ||
| 427 | r55.listen_until_close(), | ||
| 428 | r56.listen_until_close(), | ||
| 429 | ); | ||
| 430 | cli_tester_handle.join().unwrap()?; | ||
| 431 | Ok(()) | ||
| 432 | } | ||
| 433 | } | ||
| 434 | mod with_force_flag { | ||
| 435 | use super::*; | ||
| 436 | |||
| 437 | mod cli_prompts { | ||
| 438 | use super::*; | ||
| 439 | |||
| 440 | #[tokio::test] | ||
| 441 | #[serial] | ||
| 442 | async fn cli_shows_revision_sent() -> Result<()> { | ||
| 443 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 444 | Relay::new(8051, None, None), | ||
| 445 | Relay::new(8052, None, None), | ||
| 446 | Relay::new(8053, None, None), | ||
| 447 | Relay::new(8055, None, None), | ||
| 448 | Relay::new(8056, None, None), | ||
| 449 | ); | ||
| 450 | |||
| 451 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 452 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 453 | r51.events.push(generate_repo_ref_event()); | ||
| 454 | |||
| 455 | r55.events.push(generate_repo_ref_event()); | ||
| 456 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 457 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 458 | |||
| 459 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 460 | let (_, tmp_repo) = | ||
| 461 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | ||
| 462 | let branch_name = tmp_repo.get_checked_out_branch_name()?; | ||
| 463 | |||
| 464 | let test_repo = GitTestRepo::default(); | ||
| 465 | test_repo.populate()?; | ||
| 466 | |||
| 467 | // simulate rebase | ||
| 468 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | ||
| 469 | test_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 470 | create_and_populate_branch(&test_repo, &branch_name, "a", false)?; | ||
| 471 | let mut p = CliTester::new_from_dir( | ||
| 472 | &test_repo.dir, | ||
| 473 | [ | ||
| 474 | "--nsec", | ||
| 475 | TEST_KEY_1_NSEC, | ||
| 476 | "--password", | ||
| 477 | TEST_PASSWORD, | ||
| 478 | "--disable-cli-spinners", | ||
| 479 | "push", | ||
| 480 | "--force", | ||
| 481 | ], | ||
| 482 | ); | ||
| 483 | p.expect("fetching updates...\r\n")?; | ||
| 484 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 485 | p.expect("preparing to force push proposal revision...\r\n")?; | ||
| 486 | // standard output from `ngit send` | ||
| 487 | p.expect("creating proposal revision for: ")?; | ||
| 488 | // proposal id will be printed in this gap | ||
| 489 | p.expect_eventually("\r\n")?; | ||
| 490 | p.expect("creating proposal from 2 commits:\r\n")?; | ||
| 491 | p.expect("355bdf1 add a4.md\r\n")?; | ||
| 492 | p.expect("dbd1115 add a3.md\r\n")?; | ||
| 493 | p.expect("logged in as fred via cli arguments\r\n")?; | ||
| 494 | p.expect("posting 2 patches without a covering letter...\r\n")?; | ||
| 495 | |||
| 496 | relay::expect_send_with_progress( | ||
| 497 | &mut p, | ||
| 498 | vec![ | ||
| 499 | (" [my-relay] [repo-relay] ws://localhost:8055", true, ""), | ||
| 500 | (" [my-relay] ws://localhost:8053", true, ""), | ||
| 501 | (" [repo-relay] ws://localhost:8056", true, ""), | ||
| 502 | (" [default] ws://localhost:8051", true, ""), | ||
| 503 | (" [default] ws://localhost:8052", true, ""), | ||
| 504 | ], | ||
| 505 | 2, | ||
| 506 | )?; | ||
| 507 | // end standard `ngit send output` | ||
| 508 | p.expect_after_whitespace("force pushed proposal revision\r\n")?; | ||
| 509 | p.expect_end()?; | ||
| 510 | |||
| 511 | for p in [51, 52, 53, 55, 56] { | ||
| 512 | relay::shutdown_relay(8000 + p)?; | ||
| 513 | } | ||
| 514 | Ok(()) | ||
| 515 | }); | ||
| 516 | |||
| 517 | // launch relay | ||
| 518 | let _ = join!( | ||
| 519 | r51.listen_until_close(), | ||
| 520 | r52.listen_until_close(), | ||
| 521 | r53.listen_until_close(), | ||
| 522 | r55.listen_until_close(), | ||
| 523 | r56.listen_until_close(), | ||
| 524 | ); | ||
| 525 | cli_tester_handle.join().unwrap()?; | ||
| 526 | Ok(()) | ||
| 527 | } | ||
| 528 | } | ||
| 529 | } | ||
| 530 | } | ||
| 531 | } | ||