diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-24 10:58:07 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-24 10:58:07 +0100 |
| commit | 6d086a6608652193898ec548382e780733ea2f5a (patch) | |
| tree | 29515ad88e09ae82eb3239927d241da2111efad1 /tests/push.rs | |
| parent | b67376ff54abeab31422921ba5f4883d5d3dccdb (diff) | |
test: refactor `pull` and `push` to abstract code
into lib which makes reading and maintaining tests easier
Diffstat (limited to 'tests/push.rs')
| -rw-r--r-- | tests/push.rs | 279 |
1 files changed, 12 insertions, 267 deletions
diff --git a/tests/push.rs b/tests/push.rs index b771d4b..e300fe2 100644 --- a/tests/push.rs +++ b/tests/push.rs | |||
| @@ -3,94 +3,6 @@ use futures::join; | |||
| 3 | use serial_test::serial; | 3 | use serial_test::serial; |
| 4 | use test_utils::{git::GitTestRepo, relay::Relay, *}; | 4 | use test_utils::{git::GitTestRepo, relay::Relay, *}; |
| 5 | 5 | ||
| 6 | static FEATURE_BRANCH_NAME_1: &str = "feature-example-t"; | ||
| 7 | static FEATURE_BRANCH_NAME_2: &str = "feature-example-f"; | ||
| 8 | static FEATURE_BRANCH_NAME_3: &str = "feature-example-c"; | ||
| 9 | |||
| 10 | static PROPOSAL_TITLE_1: &str = "proposal a"; | ||
| 11 | static PROPOSAL_TITLE_2: &str = "proposal b"; | ||
| 12 | static PROPOSAL_TITLE_3: &str = "proposal c"; | ||
| 13 | |||
| 14 | fn cli_tester_create_proposals() -> Result<GitTestRepo> { | ||
| 15 | let git_repo = GitTestRepo::default(); | ||
| 16 | git_repo.populate()?; | ||
| 17 | cli_tester_create_proposal( | ||
| 18 | &git_repo, | ||
| 19 | FEATURE_BRANCH_NAME_1, | ||
| 20 | "a", | ||
| 21 | PROPOSAL_TITLE_1, | ||
| 22 | "proposal a description", | ||
| 23 | )?; | ||
| 24 | cli_tester_create_proposal( | ||
| 25 | &git_repo, | ||
| 26 | FEATURE_BRANCH_NAME_2, | ||
| 27 | "b", | ||
| 28 | PROPOSAL_TITLE_2, | ||
| 29 | "proposal b description", | ||
| 30 | )?; | ||
| 31 | cli_tester_create_proposal( | ||
| 32 | &git_repo, | ||
| 33 | FEATURE_BRANCH_NAME_3, | ||
| 34 | "c", | ||
| 35 | PROPOSAL_TITLE_3, | ||
| 36 | "proposal c description", | ||
| 37 | )?; | ||
| 38 | Ok(git_repo) | ||
| 39 | } | ||
| 40 | |||
| 41 | fn create_and_populate_branch( | ||
| 42 | test_repo: &GitTestRepo, | ||
| 43 | branch_name: &str, | ||
| 44 | prefix: &str, | ||
| 45 | only_one_commit: bool, | ||
| 46 | ) -> Result<()> { | ||
| 47 | test_repo.checkout("main")?; | ||
| 48 | test_repo.create_branch(branch_name)?; | ||
| 49 | test_repo.checkout(branch_name)?; | ||
| 50 | std::fs::write( | ||
| 51 | test_repo.dir.join(format!("{}3.md", prefix)), | ||
| 52 | "some content", | ||
| 53 | )?; | ||
| 54 | test_repo.stage_and_commit(format!("add {}3.md", prefix).as_str())?; | ||
| 55 | if !only_one_commit { | ||
| 56 | std::fs::write( | ||
| 57 | test_repo.dir.join(format!("{}4.md", prefix)), | ||
| 58 | "some content", | ||
| 59 | )?; | ||
| 60 | test_repo.stage_and_commit(format!("add {}4.md", prefix).as_str())?; | ||
| 61 | } | ||
| 62 | Ok(()) | ||
| 63 | } | ||
| 64 | |||
| 65 | fn cli_tester_create_proposal( | ||
| 66 | test_repo: &GitTestRepo, | ||
| 67 | branch_name: &str, | ||
| 68 | prefix: &str, | ||
| 69 | title: &str, | ||
| 70 | description: &str, | ||
| 71 | ) -> Result<()> { | ||
| 72 | create_and_populate_branch(test_repo, branch_name, prefix, false)?; | ||
| 73 | |||
| 74 | let mut p = CliTester::new_from_dir( | ||
| 75 | &test_repo.dir, | ||
| 76 | [ | ||
| 77 | "--nsec", | ||
| 78 | TEST_KEY_1_NSEC, | ||
| 79 | "--password", | ||
| 80 | TEST_PASSWORD, | ||
| 81 | "--disable-cli-spinners", | ||
| 82 | "send", | ||
| 83 | "HEAD~2", | ||
| 84 | "--title", | ||
| 85 | format!("\"{title}\"").as_str(), | ||
| 86 | "--description", | ||
| 87 | format!("\"{description}\"").as_str(), | ||
| 88 | ], | ||
| 89 | ); | ||
| 90 | p.expect_end_eventually()?; | ||
| 91 | Ok(()) | ||
| 92 | } | ||
| 93 | |||
| 94 | mod when_main_is_checked_out { | 6 | mod when_main_is_checked_out { |
| 95 | use super::*; | 7 | use super::*; |
| 96 | 8 | ||
| @@ -196,37 +108,8 @@ mod when_branch_is_checked_out { | |||
| 196 | r55.events.push(generate_test_key_1_relay_list_event()); | 108 | r55.events.push(generate_test_key_1_relay_list_event()); |
| 197 | 109 | ||
| 198 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 110 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 199 | cli_tester_create_proposals()?; | 111 | let (_, test_repo) = |
| 200 | 112 | create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; | |
| 201 | let test_repo = GitTestRepo::default(); | ||
| 202 | test_repo.populate()?; | ||
| 203 | |||
| 204 | // create proposal branch | ||
| 205 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | ||
| 206 | p.expect("fetching updates...\r\n")?; | ||
| 207 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 208 | let mut c = p.expect_choice( | ||
| 209 | "all proposals", | ||
| 210 | vec![ | ||
| 211 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 212 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 213 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 214 | ], | ||
| 215 | )?; | ||
| 216 | c.succeeds_with(2, true, None)?; | ||
| 217 | let mut c = p.expect_choice( | ||
| 218 | "", | ||
| 219 | vec![ | ||
| 220 | format!( | ||
| 221 | "create and checkout proposal branch (2 ahead 0 behind 'main')" | ||
| 222 | ), | ||
| 223 | format!("apply to current branch with `git am`"), | ||
| 224 | format!("download to ./patches"), | ||
| 225 | format!("back"), | ||
| 226 | ], | ||
| 227 | )?; | ||
| 228 | c.succeeds_with(0, false, Some(0))?; | ||
| 229 | p.expect_end_eventually()?; | ||
| 230 | 113 | ||
| 231 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); | 114 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); |
| 232 | p.expect("fetching updates...\r\n")?; | 115 | p.expect("fetching updates...\r\n")?; |
| @@ -279,37 +162,8 @@ mod when_branch_is_checked_out { | |||
| 279 | r55.events.push(generate_test_key_1_relay_list_event()); | 162 | r55.events.push(generate_test_key_1_relay_list_event()); |
| 280 | 163 | ||
| 281 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 164 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 282 | cli_tester_create_proposals()?; | 165 | let (_, test_repo) = |
| 283 | 166 | create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; | |
| 284 | let test_repo = GitTestRepo::default(); | ||
| 285 | test_repo.populate()?; | ||
| 286 | |||
| 287 | // create proposal branch | ||
| 288 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | ||
| 289 | p.expect("fetching updates...\r\n")?; | ||
| 290 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 291 | let mut c = p.expect_choice( | ||
| 292 | "all proposals", | ||
| 293 | vec![ | ||
| 294 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 295 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 296 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 297 | ], | ||
| 298 | )?; | ||
| 299 | c.succeeds_with(2, true, None)?; | ||
| 300 | let mut c = p.expect_choice( | ||
| 301 | "", | ||
| 302 | vec![ | ||
| 303 | format!( | ||
| 304 | "create and checkout proposal branch (2 ahead 0 behind 'main')" | ||
| 305 | ), | ||
| 306 | format!("apply to current branch with `git am`"), | ||
| 307 | format!("download to ./patches"), | ||
| 308 | format!("back"), | ||
| 309 | ], | ||
| 310 | )?; | ||
| 311 | c.succeeds_with(0, false, Some(0))?; | ||
| 312 | p.expect_end_eventually()?; | ||
| 313 | 167 | ||
| 314 | // remove latest commit so it is behind | 168 | // remove latest commit so it is behind |
| 315 | let branch_name = test_repo.get_checked_out_branch_name()?; | 169 | let branch_name = test_repo.get_checked_out_branch_name()?; |
| @@ -380,37 +234,9 @@ mod when_branch_is_checked_out { | |||
| 380 | 234 | ||
| 381 | let cli_tester_handle = | 235 | let cli_tester_handle = |
| 382 | std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { | 236 | std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { |
| 383 | let originating_repo = cli_tester_create_proposals()?; | 237 | let (originating_repo, test_repo) = |
| 384 | 238 | create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; | |
| 385 | let test_repo = GitTestRepo::default(); | ||
| 386 | test_repo.populate()?; | ||
| 387 | 239 | ||
| 388 | // create proposal branch | ||
| 389 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | ||
| 390 | p.expect("fetching updates...\r\n")?; | ||
| 391 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 392 | let mut c = p.expect_choice( | ||
| 393 | "all proposals", | ||
| 394 | vec![ | ||
| 395 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 396 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 397 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 398 | ], | ||
| 399 | )?; | ||
| 400 | c.succeeds_with(2, true, None)?; | ||
| 401 | let mut c = p.expect_choice( | ||
| 402 | "", | ||
| 403 | vec![ | ||
| 404 | format!( | ||
| 405 | "create and checkout proposal branch (2 ahead 0 behind 'main')" | ||
| 406 | ), | ||
| 407 | format!("apply to current branch with `git am`"), | ||
| 408 | format!("download to ./patches"), | ||
| 409 | format!("back"), | ||
| 410 | ], | ||
| 411 | )?; | ||
| 412 | c.succeeds_with(0, false, Some(0))?; | ||
| 413 | p.expect_end_eventually()?; | ||
| 414 | // add another commit (so we have an ammened local branch) | 240 | // add another commit (so we have an ammened local branch) |
| 415 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; | 241 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; |
| 416 | test_repo.stage_and_commit("add ammended-commit.md")?; | 242 | test_repo.stage_and_commit("add ammended-commit.md")?; |
| @@ -488,35 +314,9 @@ mod when_branch_is_checked_out { | |||
| 488 | r55.events.push(generate_test_key_1_relay_list_event()); | 314 | r55.events.push(generate_test_key_1_relay_list_event()); |
| 489 | 315 | ||
| 490 | let cli_tester_handle = std::thread::spawn(move || -> Result<GitTestRepo> { | 316 | let cli_tester_handle = std::thread::spawn(move || -> Result<GitTestRepo> { |
| 491 | cli_tester_create_proposals()?; | 317 | let (_, test_repo) = |
| 318 | create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; | ||
| 492 | 319 | ||
| 493 | let test_repo = GitTestRepo::default(); | ||
| 494 | test_repo.populate()?; | ||
| 495 | |||
| 496 | // create proposal branch | ||
| 497 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | ||
| 498 | p.expect("fetching updates...\r\n")?; | ||
| 499 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 500 | let mut c = p.expect_choice( | ||
| 501 | "all proposals", | ||
| 502 | vec![ | ||
| 503 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 504 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 505 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 506 | ], | ||
| 507 | )?; | ||
| 508 | c.succeeds_with(2, true, None)?; | ||
| 509 | let mut c = p.expect_choice( | ||
| 510 | "", | ||
| 511 | vec![ | ||
| 512 | format!("create and checkout proposal branch (2 ahead 0 behind 'main')"), | ||
| 513 | format!("apply to current branch with `git am`"), | ||
| 514 | format!("download to ./patches"), | ||
| 515 | format!("back"), | ||
| 516 | ], | ||
| 517 | )?; | ||
| 518 | c.succeeds_with(0, false, Some(0))?; | ||
| 519 | p.expect_end_eventually()?; | ||
| 520 | // add another commit (so we have an ammened local branch) | 320 | // add another commit (so we have an ammened local branch) |
| 521 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; | 321 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; |
| 522 | test_repo.stage_and_commit("add ammended-commit.md")?; | 322 | test_repo.stage_and_commit("add ammended-commit.md")?; |
| @@ -597,36 +397,8 @@ mod when_branch_is_checked_out { | |||
| 597 | r55.events.push(generate_test_key_1_relay_list_event()); | 397 | r55.events.push(generate_test_key_1_relay_list_event()); |
| 598 | 398 | ||
| 599 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 399 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 600 | cli_tester_create_proposals()?; | 400 | let (_, tmp_repo) = |
| 601 | 401 | create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; | |
| 602 | // discover proposal branch name | ||
| 603 | let tmp_repo = GitTestRepo::default(); | ||
| 604 | tmp_repo.populate()?; | ||
| 605 | let mut p = CliTester::new_from_dir(&tmp_repo.dir, ["list"]); | ||
| 606 | p.expect("fetching updates...\r\n")?; | ||
| 607 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 608 | let mut c = p.expect_choice( | ||
| 609 | "all proposals", | ||
| 610 | vec![ | ||
| 611 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 612 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 613 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 614 | ], | ||
| 615 | )?; | ||
| 616 | c.succeeds_with(2, true, None)?; | ||
| 617 | let mut c = p.expect_choice( | ||
| 618 | "", | ||
| 619 | vec![ | ||
| 620 | format!( | ||
| 621 | "create and checkout proposal branch (2 ahead 0 behind 'main')" | ||
| 622 | ), | ||
| 623 | format!("apply to current branch with `git am`"), | ||
| 624 | format!("download to ./patches"), | ||
| 625 | format!("back"), | ||
| 626 | ], | ||
| 627 | )?; | ||
| 628 | c.succeeds_with(0, false, Some(0))?; | ||
| 629 | p.expect_end_eventually()?; | ||
| 630 | let branch_name = tmp_repo.get_checked_out_branch_name()?; | 402 | let branch_name = tmp_repo.get_checked_out_branch_name()?; |
| 631 | 403 | ||
| 632 | let test_repo = GitTestRepo::default(); | 404 | let test_repo = GitTestRepo::default(); |
| @@ -691,35 +463,8 @@ mod when_branch_is_checked_out { | |||
| 691 | r55.events.push(generate_test_key_1_relay_list_event()); | 463 | r55.events.push(generate_test_key_1_relay_list_event()); |
| 692 | 464 | ||
| 693 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 465 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 694 | cli_tester_create_proposals()?; | 466 | let (_, tmp_repo) = |
| 695 | // discover proposal branch name | 467 | create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; |
| 696 | let tmp_repo = GitTestRepo::default(); | ||
| 697 | tmp_repo.populate()?; | ||
| 698 | let mut p = CliTester::new_from_dir(&tmp_repo.dir, ["list"]); | ||
| 699 | p.expect("fetching updates...\r\n")?; | ||
| 700 | p.expect_eventually("\r\n")?; // some updates listed here | ||
| 701 | let mut c = p.expect_choice( | ||
| 702 | "all proposals", | ||
| 703 | vec![ | ||
| 704 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 705 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 706 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 707 | ], | ||
| 708 | )?; | ||
| 709 | c.succeeds_with(2, true, None)?; | ||
| 710 | let mut c = p.expect_choice( | ||
| 711 | "", | ||
| 712 | vec![ | ||
| 713 | format!( | ||
| 714 | "create and checkout proposal branch (2 ahead 0 behind 'main')" | ||
| 715 | ), | ||
| 716 | format!("apply to current branch with `git am`"), | ||
| 717 | format!("download to ./patches"), | ||
| 718 | format!("back"), | ||
| 719 | ], | ||
| 720 | )?; | ||
| 721 | c.succeeds_with(0, false, Some(0))?; | ||
| 722 | p.expect_end_eventually()?; | ||
| 723 | let branch_name = tmp_repo.get_checked_out_branch_name()?; | 468 | let branch_name = tmp_repo.get_checked_out_branch_name()?; |
| 724 | 469 | ||
| 725 | let test_repo = GitTestRepo::default(); | 470 | let test_repo = GitTestRepo::default(); |