Skip to content

Commit 84be75a

Browse files
committed
Reduce usage of BorsTester::default_repo function
1 parent 43e8ec8 commit 84be75a

File tree

7 files changed

+43
-19
lines changed

7 files changed

+43
-19
lines changed

src/bors/handlers/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ async fn unapprove_pr(
640640

641641
#[cfg(test)]
642642
mod tests {
643-
use crate::tests::{BorsTester, Comment, User, run_test};
643+
use crate::tests::{BorsTester, Comment, User, default_repo_name, run_test};
644644

645645
#[sqlx::test]
646646
async fn ignore_bot_comment(pool: sqlx::PgPool) {
@@ -657,7 +657,9 @@ mod tests {
657657
#[sqlx::test]
658658
async fn do_not_load_pr_on_unrelated_comment(pool: sqlx::PgPool) {
659659
run_test(pool, async |tester: &mut BorsTester| {
660-
tester.default_repo().await.lock().pull_request_error = true;
660+
tester
661+
.modify_repo(&default_repo_name(), |repo| repo.pull_request_error = true)
662+
.await;
661663
tester.post_comment("no command").await?;
662664
Ok(())
663665
})

src/bors/handlers/pr_events.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,11 @@ mod tests {
682682
BorsBuilder::new(pool)
683683
.github(gh_state_with_merge_queue())
684684
.run_test(async |tester: &mut BorsTester| {
685-
tester.default_repo().await.lock().workflow_cancel_error = true;
685+
tester
686+
.modify_repo(&default_repo_name(), |repo| {
687+
repo.workflow_cancel_error = true
688+
})
689+
.await;
686690
tester.post_comment("@bors r+").await?;
687691
tester.expect_comments((), 1).await;
688692
tester.process_merge_queue().await;

src/bors/handlers/review.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ merge_queue_enabled = true
13441344
"#,
13451345
))
13461346
.run_test(async |tester: &mut BorsTester| {
1347-
tester.default_repo().await.lock().workflow_cancel_error = true;
1347+
tester.modify_repo(&default_repo_name(), |pr| pr.workflow_cancel_error = true).await;
13481348
tester.post_comment("@bors r+").await?;
13491349
tester.expect_comments((), 1).await;
13501350
tester.process_merge_queue().await;

src/bors/handlers/trybuild.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ mod tests {
433433
status: WorkflowStatus::Success,
434434
});
435435

436-
tester.default_repo().await.lock().update_workflow_run(workflow.clone(), WorkflowStatus::Pending);
436+
tester.modify_repo(&default_repo_name(), |repo| repo.update_workflow_run(workflow.clone(), WorkflowStatus::Pending)).await;
437437
tester.workflow_full_failure(workflow).await?;
438438
insta::assert_snapshot!(
439439
tester.get_comment(()).await?,
@@ -865,7 +865,7 @@ try-job: Bar
865865
#[sqlx::test]
866866
async fn try_cancel_error(pool: sqlx::PgPool) {
867867
run_test(pool, async |tester: &mut BorsTester| {
868-
tester.default_repo().await.lock().workflow_cancel_error = true;
868+
tester.modify_repo(&default_repo_name(), |repo| repo.workflow_cancel_error = true).await;
869869
tester.post_comment("@bors try").await?;
870870
tester.expect_comments((), 1).await;
871871
tester
@@ -888,7 +888,11 @@ try-job: Bar
888888
#[sqlx::test]
889889
async fn try_cancel_cancel_in_db(pool: sqlx::PgPool) {
890890
run_test(pool, async |tester: &mut BorsTester| {
891-
tester.default_repo().await.lock().workflow_cancel_error = true;
891+
tester
892+
.modify_repo(&default_repo_name(), |repo| {
893+
repo.workflow_cancel_error = true
894+
})
895+
.await;
892896
tester.post_comment("@bors try").await?;
893897
tester.expect_comments((), 1).await;
894898
tester.post_comment("@bors try cancel").await?;
@@ -912,10 +916,10 @@ try-job: Bar
912916
let w3 = WorkflowRunData::from(branch).with_run_id(3);
913917
for workflow in [&w1, &w2, &w3] {
914918
tester
915-
.default_repo()
916-
.await
917-
.lock()
918-
.update_workflow_run(workflow.clone(), WorkflowStatus::Pending);
919+
.modify_repo(&default_repo_name(), |repo| {
920+
repo.update_workflow_run(workflow.clone(), WorkflowStatus::Pending)
921+
})
922+
.await;
919923
}
920924

921925
tester.workflow_full_success(w1).await?;

src/bors/handlers/workflow.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,10 @@ mod tests {
456456
use crate::bors::merge_queue::AUTO_BUILD_CHECK_RUN_NAME;
457457
use crate::database::operations::get_all_workflows;
458458
use crate::database::{BuildStatus, WorkflowStatus};
459-
use crate::tests::BorsTester;
460459
use crate::tests::{
461460
BorsBuilder, Branch, GitHubState, WorkflowEvent, WorkflowRunData, run_test,
462461
};
462+
use crate::tests::{BorsTester, default_repo_name};
463463

464464
fn gh_state_with_merge_queue() -> GitHubState {
465465
GitHubState::default().with_default_config(
@@ -545,10 +545,11 @@ mod tests {
545545

546546
// Let the GH mock know about the existence of the second workflow
547547
tester
548-
.default_repo()
549-
.await
550-
.lock()
551-
.update_workflow_run(w2.clone(), WorkflowStatus::Pending);
548+
.modify_repo(&default_repo_name(), |repo| {
549+
repo.update_workflow_run(w2.clone(), WorkflowStatus::Pending)
550+
})
551+
.await;
552+
552553
// Finish w1 while w2 is not yet in the DB
553554
tester.workflow_full_success(w1).await?;
554555
tester.workflow_full_success(w2).await?;

src/bors/merge_queue.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,9 @@ mod tests {
506506
.await?;
507507
tester.expect_comments((), 1).await;
508508

509-
tester.default_repo().await.lock().push_error = true;
509+
tester
510+
.modify_repo(&default_repo_name(), |repo| repo.push_error = true)
511+
.await;
510512

511513
tester.process_merge_queue().await;
512514
insta::assert_snapshot!(
@@ -527,7 +529,9 @@ mod tests {
527529
.await?;
528530
tester.expect_comments((), 1).await;
529531

530-
tester.default_repo().await.lock().push_error = true;
532+
tester
533+
.modify_repo(&default_repo_name(), |repo| repo.push_error = true)
534+
.await;
531535

532536
tester.process_merge_queue().await;
533537
tester.expect_comments((), 1).await;
@@ -554,7 +558,9 @@ mod tests {
554558
.await?;
555559
tester.expect_comments((), 1).await;
556560

557-
tester.default_repo().await.lock().push_error = true;
561+
tester
562+
.modify_repo(&default_repo_name(), |repo| repo.push_error = true)
563+
.await;
558564

559565
tester.process_merge_queue().await;
560566
tester.expect_comments((), 1).await;

src/tests/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ impl BorsTester {
219219
self.github.lock().await.get_repo(name)
220220
}
221221

222+
/// Modifies the given repo state in the GitHub mock (**without sending a webhook**).
223+
pub async fn modify_repo<F: FnOnce(&mut Repo)>(&mut self, repo: &GithubRepoName, func: F) {
224+
let repo = self.github.lock().await.get_repo(repo);
225+
let mut repo = repo.lock();
226+
func(&mut repo)
227+
}
228+
222229
/// Get a PR proxy that can be used to assert various things about the PR.
223230
pub async fn get_pr<Id: Into<PrIdentifier>>(&self, id: Id) -> PullRequestProxy {
224231
let id = id.into();

0 commit comments

Comments
 (0)