diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-24 14:48:33 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-24 14:48:33 +0100 |
| commit | dc05e1ca72d4c7eec9e6aeb989c2aef35a33aab8 (patch) | |
| tree | 5cbfb0709ba88e79949a8b69ce2ef9de939928ea | |
| parent | ab8785ef986b583dbded578c5b90435adfca526f (diff) | |
test: fix `pull` tests
it was so much clearer what the problem was after
abstracting reused test code
| -rw-r--r-- | test_utils/src/lib.rs | 3 | ||||
| -rw-r--r-- | tests/list.rs | 3 | ||||
| -rw-r--r-- | tests/pull.rs | 23 |
3 files changed, 16 insertions, 13 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 087f849..866eafb 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -1196,14 +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 ammend_last_commit_and_checkout_main(test_repo: &GitTestRepo) -> Result<String> { | 1199 | pub fn amend_last_commit(test_repo: &GitTestRepo) -> 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"), "some content")?; |
| 1205 | test_repo.stage_and_commit("add ammended-commit.md")?; | 1205 | test_repo.stage_and_commit("add ammended-commit.md")?; |
| 1206 | test_repo.checkout("main")?; | ||
| 1207 | Ok(branch_name) | 1206 | Ok(branch_name) |
| 1208 | } | 1207 | } |
| 1209 | 1208 | ||
diff --git a/tests/list.rs b/tests/list.rs index c92390b..9ffc26a 100644 --- a/tests/list.rs +++ b/tests/list.rs | |||
| @@ -1105,7 +1105,8 @@ mod when_main_branch_is_uptodate { | |||
| 1105 | let (_, test_repo) = | 1105 | let (_, test_repo) = |
| 1106 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | 1106 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; |
| 1107 | 1107 | ||
| 1108 | ammend_last_commit_and_checkout_main(&test_repo)?; | 1108 | amend_last_commit(&test_repo)?; |
| 1109 | test_repo.checkout("main")?; | ||
| 1109 | 1110 | ||
| 1110 | // run test | 1111 | // run test |
| 1111 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | 1112 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); |
diff --git a/tests/pull.rs b/tests/pull.rs index 89b28c3..0b0c3ba 100644 --- a/tests/pull.rs +++ b/tests/pull.rs | |||
| @@ -203,9 +203,11 @@ mod when_branch_is_checked_out { | |||
| 203 | let (originating_repo, test_repo) = | 203 | let (originating_repo, test_repo) = |
| 204 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | 204 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; |
| 205 | 205 | ||
| 206 | remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main( | 206 | let branch_name = |
| 207 | &test_repo, | 207 | remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main( |
| 208 | )?; | 208 | &test_repo, |
| 209 | )?; | ||
| 210 | test_repo.checkout(&branch_name)?; | ||
| 209 | 211 | ||
| 210 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | 212 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); |
| 211 | p.expect_end_eventually()?; | 213 | p.expect_end_eventually()?; |
| @@ -257,9 +259,11 @@ mod when_branch_is_checked_out { | |||
| 257 | let (originating_repo, test_repo) = | 259 | let (originating_repo, test_repo) = |
| 258 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | 260 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; |
| 259 | 261 | ||
| 260 | remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main( | 262 | let branch_name = |
| 261 | &test_repo, | 263 | remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main( |
| 262 | )?; | 264 | &test_repo, |
| 265 | )?; | ||
| 266 | test_repo.checkout(&branch_name)?; | ||
| 263 | 267 | ||
| 264 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | 268 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); |
| 265 | p.expect("fetching updates...\r\n")?; | 269 | p.expect("fetching updates...\r\n")?; |
| @@ -330,10 +334,11 @@ mod when_branch_is_checked_out { | |||
| 330 | let (originating_repo, test_repo) = | 334 | let (originating_repo, test_repo) = |
| 331 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | 335 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; |
| 332 | 336 | ||
| 333 | let branch_name = ammend_last_commit_and_checkout_main(&test_repo)?; | 337 | let branch_name = amend_last_commit(&test_repo)?; |
| 334 | 338 | ||
| 335 | // create and send a revision from another repository | 339 | // create and send a revision from another repository |
| 336 | originating_repo.checkout("main")?; | 340 | originating_repo.checkout("main")?; |
| 341 | test_repo.checkout("main")?; | ||
| 337 | test_repo.git_repo.branch( | 342 | test_repo.git_repo.branch( |
| 338 | &branch_name, | 343 | &branch_name, |
| 339 | &test_repo | 344 | &test_repo |
| @@ -414,7 +419,7 @@ mod when_branch_is_checked_out { | |||
| 414 | let (_, test_repo) = | 419 | let (_, test_repo) = |
| 415 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; | 420 | create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?; |
| 416 | 421 | ||
| 417 | ammend_last_commit_and_checkout_main(&test_repo)?; | 422 | amend_last_commit(&test_repo)?; |
| 418 | 423 | ||
| 419 | // run test | 424 | // run test |
| 420 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | 425 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); |
| @@ -479,7 +484,6 @@ mod when_branch_is_checked_out { | |||
| 479 | // add another commit (so we have a local branch 1 ahead) | 484 | // add another commit (so we have a local branch 1 ahead) |
| 480 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; | 485 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; |
| 481 | test_repo.stage_and_commit("add ammended-commit.md")?; | 486 | test_repo.stage_and_commit("add ammended-commit.md")?; |
| 482 | test_repo.checkout("main")?; | ||
| 483 | 487 | ||
| 484 | // run test | 488 | // run test |
| 485 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | 489 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); |
| @@ -537,7 +541,6 @@ mod when_branch_is_checked_out { | |||
| 537 | // add another commit (so we have a local branch 1 ahead) | 541 | // add another commit (so we have a local branch 1 ahead) |
| 538 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; | 542 | std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; |
| 539 | test_repo.stage_and_commit("add ammended-commit.md")?; | 543 | test_repo.stage_and_commit("add ammended-commit.md")?; |
| 540 | test_repo.checkout("main")?; | ||
| 541 | 544 | ||
| 542 | // run test | 545 | // run test |
| 543 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | 546 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); |