diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-24 16:09:28 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-24 16:09:28 +0100 |
| commit | 50df657f45966bc6cbf4a392a815fcc2c331f888 (patch) | |
| tree | b9f904532008c80c47f9c50716a883260fefb5e1 /test_utils | |
| parent | 9078d0d80d1fe98ec9e6cd116c3dd70b6e0dd55a (diff) | |
test: abstract `list` and `pull` test code
to enable improved debugging
Diffstat (limited to 'test_utils')
| -rw-r--r-- | test_utils/src/lib.rs | 82 |
1 files changed, 56 insertions, 26 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 866eafb..5125d20 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -1196,13 +1196,13 @@ pub fn remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main( | |||
| 1196 | Ok(branch_name) | 1196 | Ok(branch_name) |
| 1197 | } | 1197 | } |
| 1198 | 1198 | ||
| 1199 | pub fn amend_last_commit(test_repo: &GitTestRepo) -> Result<String> { | 1199 | pub fn amend_last_commit(test_repo: &GitTestRepo, commit_msg: &str) -> Result<String> { |
| 1200 | let branch_name = | 1200 | let branch_name = |
| 1201 | remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(test_repo)?; | 1201 | remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(test_repo)?; |
| 1202 | // add another commit (so we have an ammened local branch) | 1202 | // add another commit (so we have an ammened local branch) |
| 1203 | test_repo.checkout(&branch_name)?; | 1203 | test_repo.checkout(&branch_name)?; |
| 1204 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; | 1204 | std::fs::write(test_repo.dir.join("ammended-commit.md"), commit_msg)?; |
| 1205 | test_repo.stage_and_commit("add ammended-commit.md")?; | 1205 | test_repo.stage_and_commit(commit_msg)?; |
| 1206 | Ok(branch_name) | 1206 | Ok(branch_name) |
| 1207 | } | 1207 | } |
| 1208 | 1208 | ||
| @@ -1210,6 +1210,33 @@ pub fn create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebas | |||
| 1210 | -> Result<(GitTestRepo, GitTestRepo)> { | 1210 | -> Result<(GitTestRepo, GitTestRepo)> { |
| 1211 | let (_, test_repo) = create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | 1211 | let (_, test_repo) = create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; |
| 1212 | 1212 | ||
| 1213 | // recreate proposal 1 on top of a another commit (like a rebase on top | ||
| 1214 | // of one extra commit) | ||
| 1215 | let second_originating_repo = GitTestRepo::default(); | ||
| 1216 | second_originating_repo.populate()?; | ||
| 1217 | std::fs::write( | ||
| 1218 | second_originating_repo.dir.join("amazing.md"), | ||
| 1219 | "some content", | ||
| 1220 | )?; | ||
| 1221 | second_originating_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 1222 | cli_tester_create_proposal( | ||
| 1223 | &second_originating_repo, | ||
| 1224 | FEATURE_BRANCH_NAME_1, | ||
| 1225 | "a", | ||
| 1226 | Some((PROPOSAL_TITLE_1, "proposal a description")), | ||
| 1227 | Some(get_first_proposal_event_id()?.to_string()), | ||
| 1228 | )?; | ||
| 1229 | |||
| 1230 | // pretend we have pulled the updated main branch | ||
| 1231 | let branch_name = test_repo.get_checked_out_branch_name()?; | ||
| 1232 | test_repo.checkout("main")?; | ||
| 1233 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | ||
| 1234 | test_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 1235 | test_repo.checkout(&branch_name)?; | ||
| 1236 | Ok((second_originating_repo, test_repo)) | ||
| 1237 | } | ||
| 1238 | |||
| 1239 | fn get_first_proposal_event_id() -> Result<nostr::EventId> { | ||
| 1213 | // get proposal id of first | 1240 | // get proposal id of first |
| 1214 | let client = Client::default(); | 1241 | let client = Client::default(); |
| 1215 | Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; | 1242 | Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; |
| @@ -1236,28 +1263,31 @@ pub fn create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebas | |||
| 1236 | }) | 1263 | }) |
| 1237 | .unwrap() | 1264 | .unwrap() |
| 1238 | .id; | 1265 | .id; |
| 1239 | // recreate proposal 1 on top of a another commit (like a rebase on top | 1266 | Ok(proposal_1_id) |
| 1240 | // of one extra commit) | 1267 | } |
| 1241 | let second_originating_repo = GitTestRepo::default(); | ||
| 1242 | second_originating_repo.populate()?; | ||
| 1243 | std::fs::write( | ||
| 1244 | second_originating_repo.dir.join("amazing.md"), | ||
| 1245 | "some content", | ||
| 1246 | )?; | ||
| 1247 | second_originating_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 1248 | cli_tester_create_proposal( | ||
| 1249 | &second_originating_repo, | ||
| 1250 | FEATURE_BRANCH_NAME_1, | ||
| 1251 | "a", | ||
| 1252 | Some((PROPOSAL_TITLE_1, "proposal a description")), | ||
| 1253 | Some(proposal_1_id.to_string()), | ||
| 1254 | )?; | ||
| 1255 | 1268 | ||
| 1256 | // pretend we have pulled the updated main branch | 1269 | pub fn create_proposals_with_first_revised_and_repo_with_unrevised_proposal_checkedout() |
| 1257 | let branch_name = test_repo.get_checked_out_branch_name()?; | 1270 | -> Result<(GitTestRepo, GitTestRepo)> { |
| 1258 | test_repo.checkout("main")?; | 1271 | let (originating_repo, test_repo) = |
| 1259 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | 1272 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; |
| 1260 | test_repo.stage_and_commit("commit for rebasing on top of")?; | 1273 | |
| 1261 | test_repo.checkout(&branch_name)?; | 1274 | use_ngit_list_to_download_and_checkout_proposal_branch(&originating_repo, 1)?; |
| 1262 | Ok((second_originating_repo, test_repo)) | 1275 | |
| 1276 | amend_last_commit(&originating_repo, "add some ammended-commit.md")?; | ||
| 1277 | |||
| 1278 | let mut p = CliTester::new_from_dir( | ||
| 1279 | &originating_repo.dir, | ||
| 1280 | [ | ||
| 1281 | "--nsec", | ||
| 1282 | TEST_KEY_1_NSEC, | ||
| 1283 | "--password", | ||
| 1284 | TEST_PASSWORD, | ||
| 1285 | "--disable-cli-spinners", | ||
| 1286 | "push", | ||
| 1287 | "--force", | ||
| 1288 | ], | ||
| 1289 | ); | ||
| 1290 | p.expect_end_eventually()?; | ||
| 1291 | |||
| 1292 | Ok((originating_repo, test_repo)) | ||
| 1263 | } | 1293 | } |