diff options
| -rw-r--r-- | test_utils/src/lib.rs | 10 | ||||
| -rw-r--r-- | tests/ngit_pr_checkout.rs | 60 |
2 files changed, 37 insertions, 33 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index ccd9d80..48273e8 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -1535,10 +1535,8 @@ pub fn use_ngit_list_to_download_and_checkout_proposal_branch( | |||
| 1535 | /// Fetch proposals into the local cache and checkout the one matching | 1535 | /// Fetch proposals into the local cache and checkout the one matching |
| 1536 | /// `branch_name_in_event` using `ngit pr checkout <id>`. | 1536 | /// `branch_name_in_event` using `ngit pr checkout <id>`. |
| 1537 | /// Requires relays to already be running. | 1537 | /// Requires relays to already be running. |
| 1538 | pub fn use_ngit_pr_checkout( | 1538 | #[allow(deprecated)] |
| 1539 | test_repo: &GitTestRepo, | 1539 | pub fn use_ngit_pr_checkout(test_repo: &GitTestRepo, branch_name_in_event: &str) -> Result<()> { |
| 1540 | branch_name_in_event: &str, | ||
| 1541 | ) -> Result<()> { | ||
| 1542 | // populate the local cache | 1540 | // populate the local cache |
| 1543 | let mut p = CliTester::new_from_dir( | 1541 | let mut p = CliTester::new_from_dir( |
| 1544 | &test_repo.dir, | 1542 | &test_repo.dir, |
| @@ -1582,9 +1580,7 @@ pub fn use_ngit_pr_checkout( | |||
| 1582 | .unwrap_or(false) | 1580 | .unwrap_or(false) |
| 1583 | }) | 1581 | }) |
| 1584 | .ok_or_else(|| { | 1582 | .ok_or_else(|| { |
| 1585 | anyhow::anyhow!( | 1583 | anyhow::anyhow!("no proposal found for branch {branch_name_in_event} in: {stdout}") |
| 1586 | "no proposal found for branch {branch_name_in_event} in: {stdout}" | ||
| 1587 | ) | ||
| 1588 | })?; | 1584 | })?; |
| 1589 | let proposal_id = entry["id"].as_str().unwrap_or_default().to_string(); | 1585 | let proposal_id = entry["id"].as_str().unwrap_or_default().to_string(); |
| 1590 | 1586 | ||
diff --git a/tests/ngit_pr_checkout.rs b/tests/ngit_pr_checkout.rs index f7d7855..b0e37eb 100644 --- a/tests/ngit_pr_checkout.rs +++ b/tests/ngit_pr_checkout.rs | |||
| @@ -5,6 +5,7 @@ use test_utils::{git::GitTestRepo, relay::Relay, *}; | |||
| 5 | 5 | ||
| 6 | /// Run `ngit pr list --json --offline` in `dir` and return the nevent id for | 6 | /// Run `ngit pr list --json --offline` in `dir` and return the nevent id for |
| 7 | /// the proposal whose branch-name matches `branch_name_in_event`. | 7 | /// the proposal whose branch-name matches `branch_name_in_event`. |
| 8 | #[allow(deprecated)] | ||
| 8 | fn get_proposal_id_for_branch(dir: &std::path::Path, branch_name_in_event: &str) -> Result<String> { | 9 | fn get_proposal_id_for_branch(dir: &std::path::Path, branch_name_in_event: &str) -> Result<String> { |
| 9 | let output = std::process::Command::new(assert_cmd::cargo::cargo_bin("ngit")) | 10 | let output = std::process::Command::new(assert_cmd::cargo::cargo_bin("ngit")) |
| 10 | .env("NGITTEST", "TRUE") | 11 | .env("NGITTEST", "TRUE") |
| @@ -33,9 +34,7 @@ fn get_proposal_id_for_branch(dir: &std::path::Path, branch_name_in_event: &str) | |||
| 33 | .unwrap_or(false) | 34 | .unwrap_or(false) |
| 34 | }) | 35 | }) |
| 35 | .ok_or_else(|| { | 36 | .ok_or_else(|| { |
| 36 | anyhow::anyhow!( | 37 | anyhow::anyhow!("no proposal found for branch {branch_name_in_event} in: {stdout}") |
| 37 | "no proposal found for branch {branch_name_in_event} in: {stdout}" | ||
| 38 | ) | ||
| 39 | })?; | 38 | })?; |
| 40 | Ok(entry["id"].as_str().unwrap_or_default().to_string()) | 39 | Ok(entry["id"].as_str().unwrap_or_default().to_string()) |
| 41 | } | 40 | } |
| @@ -45,11 +44,13 @@ fn run_pr_checkout(test_repo: &GitTestRepo, branch_name_in_event: &str) -> Resul | |||
| 45 | run_pr_checkout_with_args(test_repo, branch_name_in_event, &["--offline"]) | 44 | run_pr_checkout_with_args(test_repo, branch_name_in_event, &["--offline"]) |
| 46 | } | 45 | } |
| 47 | 46 | ||
| 48 | /// Run `ngit pr checkout --force --offline <id>` (cache must already be populated). | 47 | /// Run `ngit pr checkout --force --offline <id>` (cache must already be |
| 48 | /// populated). | ||
| 49 | fn run_pr_checkout_force(test_repo: &GitTestRepo, branch_name_in_event: &str) -> Result<()> { | 49 | fn run_pr_checkout_force(test_repo: &GitTestRepo, branch_name_in_event: &str) -> Result<()> { |
| 50 | run_pr_checkout_with_args(test_repo, branch_name_in_event, &["--force", "--offline"]) | 50 | run_pr_checkout_with_args(test_repo, branch_name_in_event, &["--force", "--offline"]) |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | #[allow(deprecated)] | ||
| 53 | fn run_pr_checkout_with_args( | 54 | fn run_pr_checkout_with_args( |
| 54 | test_repo: &GitTestRepo, | 55 | test_repo: &GitTestRepo, |
| 55 | branch_name_in_event: &str, | 56 | branch_name_in_event: &str, |
| @@ -150,7 +151,9 @@ mod when_proposal_branch_doesnt_exist { | |||
| 150 | let (_, test_repo) = prep_and_run().await?; | 151 | let (_, test_repo) = prep_and_run().await?; |
| 151 | let expected_branch = get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?; | 152 | let expected_branch = get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?; |
| 152 | assert!( | 153 | assert!( |
| 153 | test_repo.get_local_branch_names()?.contains(&expected_branch), | 154 | test_repo |
| 155 | .get_local_branch_names()? | ||
| 156 | .contains(&expected_branch), | ||
| 154 | "expected branch {expected_branch} to exist" | 157 | "expected branch {expected_branch} to exist" |
| 155 | ); | 158 | ); |
| 156 | Ok(()) | 159 | Ok(()) |
| @@ -173,9 +176,10 @@ mod when_proposal_branch_doesnt_exist { | |||
| 173 | let (originating_repo, test_repo) = prep_and_run().await?; | 176 | let (originating_repo, test_repo) = prep_and_run().await?; |
| 174 | assert_eq!( | 177 | assert_eq!( |
| 175 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | 178 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, |
| 176 | test_repo.get_tip_of_local_branch( | 179 | test_repo.get_tip_of_local_branch(&get_proposal_branch_name( |
| 177 | &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)? | 180 | &test_repo, |
| 178 | )?, | 181 | FEATURE_BRANCH_NAME_1 |
| 182 | )?)?, | ||
| 179 | ); | 183 | ); |
| 180 | Ok(()) | 184 | Ok(()) |
| 181 | } | 185 | } |
| @@ -232,9 +236,10 @@ mod when_proposal_branch_exists_and_is_up_to_date { | |||
| 232 | let (originating_repo, test_repo) = prep_and_run().await?; | 236 | let (originating_repo, test_repo) = prep_and_run().await?; |
| 233 | assert_eq!( | 237 | assert_eq!( |
| 234 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | 238 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, |
| 235 | test_repo.get_tip_of_local_branch( | 239 | test_repo.get_tip_of_local_branch(&get_proposal_branch_name( |
| 236 | &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)? | 240 | &test_repo, |
| 237 | )?, | 241 | FEATURE_BRANCH_NAME_1 |
| 242 | )?)?, | ||
| 238 | ); | 243 | ); |
| 239 | Ok(()) | 244 | Ok(()) |
| 240 | } | 245 | } |
| @@ -292,9 +297,10 @@ mod when_proposal_branch_exists_and_is_behind { | |||
| 292 | let (originating_repo, test_repo) = prep_and_run().await?; | 297 | let (originating_repo, test_repo) = prep_and_run().await?; |
| 293 | assert_eq!( | 298 | assert_eq!( |
| 294 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | 299 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, |
| 295 | test_repo.get_tip_of_local_branch( | 300 | test_repo.get_tip_of_local_branch(&get_proposal_branch_name( |
| 296 | &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)? | 301 | &test_repo, |
| 297 | )?, | 302 | FEATURE_BRANCH_NAME_1 |
| 303 | )?)?, | ||
| 298 | ); | 304 | ); |
| 299 | Ok(()) | 305 | Ok(()) |
| 300 | } | 306 | } |
| @@ -343,12 +349,14 @@ mod when_proposal_branch_has_local_amendments { | |||
| 343 | #[serial] | 349 | #[serial] |
| 344 | async fn local_unpublished_commits_are_not_overwritten() -> Result<()> { | 350 | async fn local_unpublished_commits_are_not_overwritten() -> Result<()> { |
| 345 | let (originating_repo, test_repo) = prep_and_run().await?; | 351 | let (originating_repo, test_repo) = prep_and_run().await?; |
| 346 | // the local branch tip must differ from the published tip — local work preserved | 352 | // the local branch tip must differ from the published tip — local work |
| 353 | // preserved | ||
| 347 | assert_ne!( | 354 | assert_ne!( |
| 348 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | 355 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, |
| 349 | test_repo.get_tip_of_local_branch( | 356 | test_repo.get_tip_of_local_branch(&get_proposal_branch_name( |
| 350 | &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)? | 357 | &test_repo, |
| 351 | )?, | 358 | FEATURE_BRANCH_NAME_1 |
| 359 | )?)?, | ||
| 352 | ); | 360 | ); |
| 353 | Ok(()) | 361 | Ok(()) |
| 354 | } | 362 | } |
| @@ -488,9 +496,10 @@ mod when_newer_revision_rebases_proposal { | |||
| 488 | let (new_originating_repo, test_repo) = prep_and_run().await?; | 496 | let (new_originating_repo, test_repo) = prep_and_run().await?; |
| 489 | assert_eq!( | 497 | assert_eq!( |
| 490 | new_originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | 498 | new_originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, |
| 491 | test_repo.get_tip_of_local_branch( | 499 | test_repo.get_tip_of_local_branch(&get_proposal_branch_name( |
| 492 | &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)? | 500 | &test_repo, |
| 493 | )?, | 501 | FEATURE_BRANCH_NAME_1 |
| 502 | )?)?, | ||
| 494 | ); | 503 | ); |
| 495 | Ok(()) | 504 | Ok(()) |
| 496 | } | 505 | } |
| @@ -498,16 +507,15 @@ mod when_newer_revision_rebases_proposal { | |||
| 498 | 507 | ||
| 499 | /// Creates 3 proposals, checks out proposal 1 in a test repo, then publishes | 508 | /// Creates 3 proposals, checks out proposal 1 in a test repo, then publishes |
| 500 | /// a rebased revision of proposal 1 from a second originating repo. Returns | 509 | /// a rebased revision of proposal 1 from a second originating repo. Returns |
| 501 | /// (new_originating_repo, test_repo) with the test repo still on the old branch. | 510 | /// (new_originating_repo, test_repo) with the test repo still on the old |
| 502 | fn create_proposals_with_rebased_first_proposal( | 511 | /// branch. |
| 503 | ) -> Result<(GitTestRepo, GitTestRepo)> { | 512 | fn create_proposals_with_rebased_first_proposal() -> Result<(GitTestRepo, GitTestRepo)> { |
| 504 | // create the initial 3 proposals and check out proposal 1 in a test repo | 513 | // create the initial 3 proposals and check out proposal 1 in a test repo |
| 505 | let (_, test_repo) = | 514 | let (_, test_repo) = |
| 506 | create_proposals_and_repo_with_proposal_branch_checked_out(FEATURE_BRANCH_NAME_1)?; | 515 | create_proposals_and_repo_with_proposal_branch_checked_out(FEATURE_BRANCH_NAME_1)?; |
| 507 | 516 | ||
| 508 | // get the original proposal id to use as in_reply_to for the rebased revision | 517 | // get the original proposal id to use as in_reply_to for the rebased revision |
| 509 | let original_proposal_id = | 518 | let original_proposal_id = get_proposal_id_for_branch(&test_repo.dir, FEATURE_BRANCH_NAME_1)?; |
| 510 | get_proposal_id_for_branch(&test_repo.dir, FEATURE_BRANCH_NAME_1)?; | ||
| 511 | 519 | ||
| 512 | // publish a rebased revision of proposal 1 from a second originating repo | 520 | // publish a rebased revision of proposal 1 from a second originating repo |
| 513 | let second_originating_repo = GitTestRepo::default(); | 521 | let second_originating_repo = GitTestRepo::default(); |