upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-07-24 10:58:07 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-07-24 10:58:07 +0100
commit6d086a6608652193898ec548382e780733ea2f5a (patch)
tree29515ad88e09ae82eb3239927d241da2111efad1
parentb67376ff54abeab31422921ba5f4883d5d3dccdb (diff)
test: refactor `pull` and `push` to abstract code
into lib which makes reading and maintaining tests easier
-rw-r--r--test_utils/src/lib.rs166
-rw-r--r--tests/pull.rs446
-rw-r--r--tests/push.rs279
3 files changed, 197 insertions, 694 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index de7aee5..5cc6dd5 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -993,3 +993,169 @@ pub fn get_proposal_branch_name(
993 } 993 }
994 bail!("cannot find proposal root with branch-name tag matching title") 994 bail!("cannot find proposal root with branch-name tag matching title")
995} 995}
996
997pub static FEATURE_BRANCH_NAME_1: &str = "feature-example-t";
998pub static FEATURE_BRANCH_NAME_2: &str = "feature-example-f";
999pub static FEATURE_BRANCH_NAME_3: &str = "feature-example-c";
1000
1001pub static PROPOSAL_TITLE_1: &str = "proposal a";
1002pub static PROPOSAL_TITLE_2: &str = "proposal b";
1003pub static PROPOSAL_TITLE_3: &str = "proposal c";
1004
1005pub fn cli_tester_create_proposals() -> Result<GitTestRepo> {
1006 let git_repo = GitTestRepo::default();
1007 git_repo.populate()?;
1008 cli_tester_create_proposal(
1009 &git_repo,
1010 FEATURE_BRANCH_NAME_1,
1011 "a",
1012 Some((PROPOSAL_TITLE_1, "proposal a description")),
1013 None,
1014 )?;
1015 cli_tester_create_proposal(
1016 &git_repo,
1017 FEATURE_BRANCH_NAME_2,
1018 "b",
1019 Some((PROPOSAL_TITLE_2, "proposal b description")),
1020 None,
1021 )?;
1022 cli_tester_create_proposal(
1023 &git_repo,
1024 FEATURE_BRANCH_NAME_3,
1025 "c",
1026 Some((PROPOSAL_TITLE_3, "proposal c description")),
1027 None,
1028 )?;
1029 Ok(git_repo)
1030}
1031
1032pub fn create_and_populate_branch(
1033 test_repo: &GitTestRepo,
1034 branch_name: &str,
1035 prefix: &str,
1036 only_one_commit: bool,
1037) -> Result<()> {
1038 test_repo.checkout("main")?;
1039 test_repo.create_branch(branch_name)?;
1040 test_repo.checkout(branch_name)?;
1041 std::fs::write(
1042 test_repo.dir.join(format!("{}3.md", prefix)),
1043 "some content",
1044 )?;
1045 test_repo.stage_and_commit(format!("add {}3.md", prefix).as_str())?;
1046 if !only_one_commit {
1047 std::fs::write(
1048 test_repo.dir.join(format!("{}4.md", prefix)),
1049 "some content",
1050 )?;
1051 test_repo.stage_and_commit(format!("add {}4.md", prefix).as_str())?;
1052 }
1053 Ok(())
1054}
1055
1056pub fn cli_tester_create_proposal(
1057 test_repo: &GitTestRepo,
1058 branch_name: &str,
1059 prefix: &str,
1060 cover_letter_title_and_description: Option<(&str, &str)>,
1061 in_reply_to: Option<String>,
1062) -> Result<()> {
1063 create_and_populate_branch(test_repo, branch_name, prefix, false)?;
1064
1065 if let Some(in_reply_to) = in_reply_to {
1066 let mut p = CliTester::new_from_dir(
1067 &test_repo.dir,
1068 [
1069 "--nsec",
1070 TEST_KEY_1_NSEC,
1071 "--password",
1072 TEST_PASSWORD,
1073 "--disable-cli-spinners",
1074 "send",
1075 "HEAD~2",
1076 "--no-cover-letter",
1077 "--in-reply-to",
1078 in_reply_to.as_str(),
1079 ],
1080 );
1081 p.expect_end_eventually()?;
1082 } else if let Some((title, description)) = cover_letter_title_and_description {
1083 let mut p = CliTester::new_from_dir(
1084 &test_repo.dir,
1085 [
1086 "--nsec",
1087 TEST_KEY_1_NSEC,
1088 "--password",
1089 TEST_PASSWORD,
1090 "--disable-cli-spinners",
1091 "send",
1092 "HEAD~2",
1093 "--title",
1094 format!("\"{title}\"").as_str(),
1095 "--description",
1096 format!("\"{description}\"").as_str(),
1097 ],
1098 );
1099 p.expect_end_eventually()?;
1100 } else {
1101 let mut p = CliTester::new_from_dir(
1102 &test_repo.dir,
1103 [
1104 "--nsec",
1105 TEST_KEY_1_NSEC,
1106 "--password",
1107 TEST_PASSWORD,
1108 "--disable-cli-spinners",
1109 "send",
1110 "HEAD~2",
1111 "--no-cover-letter",
1112 ],
1113 );
1114 p.expect_end_eventually()?;
1115 }
1116 Ok(())
1117}
1118/// returns (originating_repo, test_repo)
1119pub fn create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()
1120-> Result<(GitTestRepo, GitTestRepo)> {
1121 Ok((
1122 cli_tester_create_proposals()?,
1123 create_repo_with_first_proposal_branch_pulled_and_checkedout()?,
1124 ))
1125}
1126
1127pub fn create_repo_with_first_proposal_branch_pulled_and_checkedout() -> Result<GitTestRepo> {
1128 let test_repo = GitTestRepo::default();
1129 test_repo.populate()?;
1130 use_ngit_list_to_download_and_checkout_first_proposal_branch(&test_repo)?;
1131 Ok(test_repo)
1132}
1133
1134pub fn use_ngit_list_to_download_and_checkout_first_proposal_branch(
1135 test_repo: &GitTestRepo,
1136) -> Result<()> {
1137 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1138 p.expect("fetching updates...\r\n")?;
1139 p.expect_eventually("\r\n")?; // some updates listed here
1140 let mut c = p.expect_choice(
1141 "all proposals",
1142 vec![
1143 format!("\"{PROPOSAL_TITLE_3}\""),
1144 format!("\"{PROPOSAL_TITLE_2}\""),
1145 format!("\"{PROPOSAL_TITLE_1}\""),
1146 ],
1147 )?;
1148 c.succeeds_with(2, true, None)?;
1149 let mut c = p.expect_choice(
1150 "",
1151 vec![
1152 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1153 format!("apply to current branch with `git am`"),
1154 format!("download to ./patches"),
1155 format!("back"),
1156 ],
1157 )?;
1158 c.succeeds_with(0, false, Some(0))?;
1159 p.expect_end_eventually()?;
1160 Ok(())
1161}
diff --git a/tests/pull.rs b/tests/pull.rs
index 0febd5c..70319bd 100644
--- a/tests/pull.rs
+++ b/tests/pull.rs
@@ -3,128 +3,6 @@ use futures::join;
3use serial_test::serial; 3use serial_test::serial;
4use test_utils::{git::GitTestRepo, relay::Relay, *}; 4use test_utils::{git::GitTestRepo, relay::Relay, *};
5 5
6static FEATURE_BRANCH_NAME_1: &str = "feature-example-t";
7static FEATURE_BRANCH_NAME_2: &str = "feature-example-f";
8static FEATURE_BRANCH_NAME_3: &str = "feature-example-c";
9
10static PROPOSAL_TITLE_1: &str = "proposal a";
11static PROPOSAL_TITLE_2: &str = "proposal b";
12static PROPOSAL_TITLE_3: &str = "proposal c";
13
14fn 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 Some((PROPOSAL_TITLE_1, "proposal a description")),
22 None,
23 )?;
24 cli_tester_create_proposal(
25 &git_repo,
26 FEATURE_BRANCH_NAME_2,
27 "b",
28 Some((PROPOSAL_TITLE_2, "proposal b description")),
29 None,
30 )?;
31 cli_tester_create_proposal(
32 &git_repo,
33 FEATURE_BRANCH_NAME_3,
34 "c",
35 Some((PROPOSAL_TITLE_3, "proposal c description")),
36 None,
37 )?;
38 Ok(git_repo)
39}
40
41fn 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
65fn cli_tester_create_proposal(
66 test_repo: &GitTestRepo,
67 branch_name: &str,
68 prefix: &str,
69 cover_letter_title_and_description: Option<(&str, &str)>,
70 in_reply_to: Option<String>,
71) -> Result<()> {
72 create_and_populate_branch(test_repo, branch_name, prefix, false)?;
73
74 if let Some(in_reply_to) = in_reply_to {
75 let mut p = CliTester::new_from_dir(
76 &test_repo.dir,
77 [
78 "--nsec",
79 TEST_KEY_1_NSEC,
80 "--password",
81 TEST_PASSWORD,
82 "--disable-cli-spinners",
83 "send",
84 "HEAD~2",
85 "--no-cover-letter",
86 "--in-reply-to",
87 in_reply_to.as_str(),
88 ],
89 );
90 p.expect_end_eventually()?;
91 } else if let Some((title, description)) = cover_letter_title_and_description {
92 let mut p = CliTester::new_from_dir(
93 &test_repo.dir,
94 [
95 "--nsec",
96 TEST_KEY_1_NSEC,
97 "--password",
98 TEST_PASSWORD,
99 "--disable-cli-spinners",
100 "send",
101 "HEAD~2",
102 "--title",
103 format!("\"{title}\"").as_str(),
104 "--description",
105 format!("\"{description}\"").as_str(),
106 ],
107 );
108 p.expect_end_eventually()?;
109 } else {
110 let mut p = CliTester::new_from_dir(
111 &test_repo.dir,
112 [
113 "--nsec",
114 TEST_KEY_1_NSEC,
115 "--password",
116 TEST_PASSWORD,
117 "--disable-cli-spinners",
118 "send",
119 "HEAD~2",
120 "--no-cover-letter",
121 ],
122 );
123 p.expect_end_eventually()?;
124 }
125 Ok(())
126}
127
128mod when_main_is_checked_out { 6mod when_main_is_checked_out {
129 use super::*; 7 use super::*;
130 8
@@ -153,33 +31,8 @@ mod when_main_is_checked_out {
153 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 31 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
154 cli_tester_create_proposals()?; 32 cli_tester_create_proposals()?;
155 33
156 let test_repo = GitTestRepo::default(); 34 let test_repo = create_repo_with_first_proposal_branch_pulled_and_checkedout()?;
157 test_repo.populate()?;
158 35
159 // create proposal branch
160 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
161 p.expect("fetching updates...\r\n")?;
162 p.expect_eventually("\r\n")?; // some updates listed here
163 let mut c = p.expect_choice(
164 "all proposals",
165 vec![
166 format!("\"{PROPOSAL_TITLE_3}\""),
167 format!("\"{PROPOSAL_TITLE_2}\""),
168 format!("\"{PROPOSAL_TITLE_1}\""),
169 ],
170 )?;
171 c.succeeds_with(2, true, None)?;
172 let mut c = p.expect_choice(
173 "",
174 vec![
175 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
176 format!("apply to current branch with `git am`"),
177 format!("download to ./patches"),
178 format!("back"),
179 ],
180 )?;
181 c.succeeds_with(0, false, Some(0))?;
182 p.expect_end_eventually()?;
183 test_repo.checkout("main")?; 36 test_repo.checkout("main")?;
184 37
185 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 38 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
@@ -295,37 +148,8 @@ mod when_branch_is_checked_out {
295 r55.events.push(generate_test_key_1_relay_list_event()); 148 r55.events.push(generate_test_key_1_relay_list_event());
296 149
297 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 150 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
298 cli_tester_create_proposals()?; 151 let (_, test_repo) =
299 152 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
300 let test_repo = GitTestRepo::default();
301 test_repo.populate()?;
302
303 // create proposal branch
304 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
305 p.expect("fetching updates...\r\n")?;
306 p.expect_eventually("\r\n")?; // some updates listed here
307 let mut c = p.expect_choice(
308 "all proposals",
309 vec![
310 format!("\"{PROPOSAL_TITLE_3}\""),
311 format!("\"{PROPOSAL_TITLE_2}\""),
312 format!("\"{PROPOSAL_TITLE_1}\""),
313 ],
314 )?;
315 c.succeeds_with(2, true, None)?;
316 let mut c = p.expect_choice(
317 "",
318 vec![
319 format!(
320 "create and checkout proposal branch (2 ahead 0 behind 'main')"
321 ),
322 format!("apply to current branch with `git am`"),
323 format!("download to ./patches"),
324 format!("back"),
325 ],
326 )?;
327 c.succeeds_with(0, false, Some(0))?;
328 p.expect_end_eventually()?;
329 153
330 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 154 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
331 p.expect("fetching updates...\r\n")?; 155 p.expect("fetching updates...\r\n")?;
@@ -376,37 +200,8 @@ mod when_branch_is_checked_out {
376 200
377 let cli_tester_handle = 201 let cli_tester_handle =
378 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 202 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> {
379 let originating_repo = cli_tester_create_proposals()?; 203 let (originating_repo, test_repo) =
380 204 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
381 let test_repo = GitTestRepo::default();
382 test_repo.populate()?;
383
384 // create proposal branch
385 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
386 p.expect("fetching updates...\r\n")?;
387 p.expect_eventually("\r\n")?; // some updates listed here
388 let mut c = p.expect_choice(
389 "all proposals",
390 vec![
391 format!("\"{PROPOSAL_TITLE_3}\""),
392 format!("\"{PROPOSAL_TITLE_2}\""),
393 format!("\"{PROPOSAL_TITLE_1}\""),
394 ],
395 )?;
396 c.succeeds_with(2, true, None)?;
397 let mut c = p.expect_choice(
398 "",
399 vec![
400 format!(
401 "create and checkout proposal branch (2 ahead 0 behind 'main')"
402 ),
403 format!("apply to current branch with `git am`"),
404 format!("download to ./patches"),
405 format!("back"),
406 ],
407 )?;
408 c.succeeds_with(0, false, Some(0))?;
409 p.expect_end_eventually()?;
410 205
411 // remove latest commit so it is behind 206 // remove latest commit so it is behind
412 let branch_name = test_repo.get_checked_out_branch_name()?; 207 let branch_name = test_repo.get_checked_out_branch_name()?;
@@ -467,37 +262,8 @@ mod when_branch_is_checked_out {
467 262
468 let cli_tester_handle = 263 let cli_tester_handle =
469 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 264 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> {
470 let originating_repo = cli_tester_create_proposals()?; 265 let (originating_repo, test_repo) =
471 266 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
472 let test_repo = GitTestRepo::default();
473 test_repo.populate()?;
474
475 // create proposal branch
476 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
477 p.expect("fetching updates...\r\n")?;
478 p.expect_eventually("\r\n")?; // some updates listed here
479 let mut c = p.expect_choice(
480 "all proposals",
481 vec![
482 format!("\"{PROPOSAL_TITLE_3}\""),
483 format!("\"{PROPOSAL_TITLE_2}\""),
484 format!("\"{PROPOSAL_TITLE_1}\""),
485 ],
486 )?;
487 c.succeeds_with(2, true, None)?;
488 let mut c = p.expect_choice(
489 "",
490 vec![
491 format!(
492 "create and checkout proposal branch (2 ahead 0 behind 'main')"
493 ),
494 format!("apply to current branch with `git am`"),
495 format!("download to ./patches"),
496 format!("back"),
497 ],
498 )?;
499 c.succeeds_with(0, false, Some(0))?;
500 p.expect_end_eventually()?;
501 267
502 // remove latest commit so it is behind 268 // remove latest commit so it is behind
503 let branch_name = test_repo.get_checked_out_branch_name()?; 269 let branch_name = test_repo.get_checked_out_branch_name()?;
@@ -577,37 +343,8 @@ mod when_branch_is_checked_out {
577 r55.events.push(generate_test_key_1_relay_list_event()); 343 r55.events.push(generate_test_key_1_relay_list_event());
578 344
579 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 345 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
580 let originating_repo = cli_tester_create_proposals()?; 346 let (originating_repo, test_repo) =
581 347 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
582 let test_repo = GitTestRepo::default();
583 test_repo.populate()?;
584
585 // create proposal branch
586 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
587 p.expect("fetching updates...\r\n")?;
588 p.expect_eventually("\r\n")?; // some updates listed here
589 let mut c = p.expect_choice(
590 "all proposals",
591 vec![
592 format!("\"{PROPOSAL_TITLE_3}\""),
593 format!("\"{PROPOSAL_TITLE_2}\""),
594 format!("\"{PROPOSAL_TITLE_1}\""),
595 ],
596 )?;
597 c.succeeds_with(2, true, None)?;
598 let mut c = p.expect_choice(
599 "",
600 vec![
601 format!(
602 "create and checkout proposal branch (2 ahead 0 behind 'main')"
603 ),
604 format!("apply to current branch with `git am`"),
605 format!("download to ./patches"),
606 format!("back"),
607 ],
608 )?;
609 c.succeeds_with(0, false, Some(0))?;
610 p.expect_end_eventually()?;
611 348
612 // remove latest commit so it is behind 349 // remove latest commit so it is behind
613 let branch_name = test_repo.get_checked_out_branch_name()?; 350 let branch_name = test_repo.get_checked_out_branch_name()?;
@@ -705,37 +442,8 @@ mod when_branch_is_checked_out {
705 r55.events.push(generate_test_key_1_relay_list_event()); 442 r55.events.push(generate_test_key_1_relay_list_event());
706 443
707 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 444 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
708 cli_tester_create_proposals()?; 445 let (_, test_repo) =
709 446 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
710 let test_repo = GitTestRepo::default();
711 test_repo.populate()?;
712
713 // create proposal branch
714 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
715 p.expect("fetching updates...\r\n")?;
716 p.expect_eventually("\r\n")?; // some updates listed here
717 let mut c = p.expect_choice(
718 "all proposals",
719 vec![
720 format!("\"{PROPOSAL_TITLE_3}\""),
721 format!("\"{PROPOSAL_TITLE_2}\""),
722 format!("\"{PROPOSAL_TITLE_1}\""),
723 ],
724 )?;
725 c.succeeds_with(2, true, None)?;
726 let mut c = p.expect_choice(
727 "",
728 vec![
729 format!(
730 "create and checkout proposal branch (2 ahead 0 behind 'main')"
731 ),
732 format!("apply to current branch with `git am`"),
733 format!("download to ./patches"),
734 format!("back"),
735 ],
736 )?;
737 c.succeeds_with(0, false, Some(0))?;
738 p.expect_end_eventually()?;
739 447
740 // remove latest commit so it is behind 448 // remove latest commit so it is behind
741 let branch_name = test_repo.get_checked_out_branch_name()?; 449 let branch_name = test_repo.get_checked_out_branch_name()?;
@@ -811,37 +519,8 @@ mod when_branch_is_checked_out {
811 519
812 let cli_tester_handle = std::thread::spawn( 520 let cli_tester_handle = std::thread::spawn(
813 move || -> Result<(GitTestRepo, GitTestRepo)> { 521 move || -> Result<(GitTestRepo, GitTestRepo)> {
814 let originating_repo = cli_tester_create_proposals()?; 522 let (originating_repo, test_repo) =
815 523 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
816 let test_repo = GitTestRepo::default();
817 test_repo.populate()?;
818
819 // create proposal branch
820 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
821 p.expect("fetching updates...\r\n")?;
822 p.expect_eventually("\r\n")?; // some updates listed here
823 let mut c = p.expect_choice(
824 "all proposals",
825 vec![
826 format!("\"{PROPOSAL_TITLE_3}\""),
827 format!("\"{PROPOSAL_TITLE_2}\""),
828 format!("\"{PROPOSAL_TITLE_1}\""),
829 ],
830 )?;
831 c.succeeds_with(2, true, None)?;
832 let mut c = p.expect_choice(
833 "",
834 vec![
835 format!(
836 "create and checkout proposal branch (2 ahead 0 behind 'main')"
837 ),
838 format!("apply to current branch with `git am`"),
839 format!("download to ./patches"),
840 format!("back"),
841 ],
842 )?;
843 c.succeeds_with(0, false, Some(0))?;
844 p.expect_end_eventually()?;
845 524
846 // add another commit (so we have a local branch 1 ahead) 525 // add another commit (so we have a local branch 1 ahead)
847 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; 526 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
@@ -898,37 +577,8 @@ mod when_branch_is_checked_out {
898 r55.events.push(generate_test_key_1_relay_list_event()); 577 r55.events.push(generate_test_key_1_relay_list_event());
899 578
900 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 579 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
901 cli_tester_create_proposals()?; 580 let (_, test_repo) =
902 581 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
903 let test_repo = GitTestRepo::default();
904 test_repo.populate()?;
905
906 // create proposal branch
907 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
908 p.expect("fetching updates...\r\n")?;
909 p.expect_eventually("\r\n")?; // some updates listed here
910 let mut c = p.expect_choice(
911 "all proposals",
912 vec![
913 format!("\"{PROPOSAL_TITLE_3}\""),
914 format!("\"{PROPOSAL_TITLE_2}\""),
915 format!("\"{PROPOSAL_TITLE_1}\""),
916 ],
917 )?;
918 c.succeeds_with(2, true, None)?;
919 let mut c = p.expect_choice(
920 "",
921 vec![
922 format!(
923 "create and checkout proposal branch (2 ahead 0 behind 'main')"
924 ),
925 format!("apply to current branch with `git am`"),
926 format!("download to ./patches"),
927 format!("back"),
928 ],
929 )?;
930 c.succeeds_with(0, false, Some(0))?;
931 p.expect_end_eventually()?;
932 582
933 // add another commit (so we have a local branch 1 ahead) 583 // add another commit (so we have a local branch 1 ahead)
934 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; 584 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
@@ -1004,37 +654,8 @@ mod when_branch_is_checked_out {
1004 654
1005 let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> = 655 let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> =
1006 tokio::task::spawn_blocking(move || { 656 tokio::task::spawn_blocking(move || {
1007 // create 3 proposals 657 let (_, test_repo) =
1008 let _ = cli_tester_create_proposals()?; 658 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
1009 // download the origianl version of the first proposal
1010 let test_repo = GitTestRepo::default();
1011 test_repo.populate()?;
1012
1013 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1014 p.expect("fetching updates...\r\n")?;
1015 p.expect_eventually("\r\n")?; // some updates listed here
1016 let mut c = p.expect_choice(
1017 "all proposals",
1018 vec![
1019 format!("\"{PROPOSAL_TITLE_3}\""),
1020 format!("\"{PROPOSAL_TITLE_2}\""),
1021 format!("\"{PROPOSAL_TITLE_1}\""),
1022 ],
1023 )?;
1024 c.succeeds_with(2, true, None)?;
1025 let mut c = p.expect_choice(
1026 "",
1027 vec![
1028 format!(
1029 "create and checkout proposal branch (2 ahead 0 behind 'main')"
1030 ),
1031 format!("apply to current branch with `git am`"),
1032 format!("download to ./patches"),
1033 format!("back"),
1034 ],
1035 )?;
1036 c.succeeds_with(0, false, Some(0))?;
1037 p.expect_end_eventually()?;
1038 659
1039 // get proposal id of first 660 // get proposal id of first
1040 let client = Client::default(); 661 let client = Client::default();
@@ -1131,37 +752,8 @@ mod when_branch_is_checked_out {
1131 752
1132 let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking( 753 let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking(
1133 move || { 754 move || {
1134 // create 3 proposals 755 let (_, test_repo) =
1135 let _ = cli_tester_create_proposals()?; 756 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
1136 // download the origianl version of the first proposal
1137 let test_repo = GitTestRepo::default();
1138 test_repo.populate()?;
1139
1140 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1141 p.expect("fetching updates...\r\n")?;
1142 p.expect_eventually("\r\n")?; // some updates listed here
1143 let mut c = p.expect_choice(
1144 "all proposals",
1145 vec![
1146 format!("\"{PROPOSAL_TITLE_3}\""),
1147 format!("\"{PROPOSAL_TITLE_2}\""),
1148 format!("\"{PROPOSAL_TITLE_1}\""),
1149 ],
1150 )?;
1151 c.succeeds_with(2, true, None)?;
1152 let mut c = p.expect_choice(
1153 "",
1154 vec![
1155 format!(
1156 "create and checkout proposal branch (2 ahead 0 behind 'main')"
1157 ),
1158 format!("apply to current branch with `git am`"),
1159 format!("download to ./patches"),
1160 format!("back"),
1161 ],
1162 )?;
1163 c.succeeds_with(0, false, Some(0))?;
1164 p.expect_end_eventually()?;
1165 757
1166 // get proposal id of first 758 // get proposal id of first
1167 let client = Client::default(); 759 let client = Client::default();
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;
3use serial_test::serial; 3use serial_test::serial;
4use test_utils::{git::GitTestRepo, relay::Relay, *}; 4use test_utils::{git::GitTestRepo, relay::Relay, *};
5 5
6static FEATURE_BRANCH_NAME_1: &str = "feature-example-t";
7static FEATURE_BRANCH_NAME_2: &str = "feature-example-f";
8static FEATURE_BRANCH_NAME_3: &str = "feature-example-c";
9
10static PROPOSAL_TITLE_1: &str = "proposal a";
11static PROPOSAL_TITLE_2: &str = "proposal b";
12static PROPOSAL_TITLE_3: &str = "proposal c";
13
14fn 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
41fn 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
65fn 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
94mod when_main_is_checked_out { 6mod 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();