Skip to content

Commit c209b22

Browse files
authored
Merge pull request #524 from Kobzol/label-opt-test
Add test for label optimization
2 parents c8f83e1 + 2e106e2 commit c209b22

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

src/bors/handlers/review.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,35 @@ mod tests {
521521
.await;
522522
}
523523

524+
#[sqlx::test]
525+
async fn approve_do_not_unnecessarily_modify_labels(pool: sqlx::PgPool) {
526+
let gh = GitHub::default().with_default_config(
527+
r#"
528+
[labels]
529+
approved = ["+foo", "+baz", "-bar", "-foo2"]
530+
"#,
531+
);
532+
run_test((pool, gh), async |ctx: &mut BorsTester| {
533+
let pr = ctx
534+
.open_pr((), |pr| {
535+
pr.labels.push("foo".to_string());
536+
pr.labels.push("foo2".to_string());
537+
})
538+
.await?;
539+
ctx.post_comment(Comment::new(pr.id(), "@bors r+")).await?;
540+
ctx.expect_comments(pr.id(), 1).await;
541+
542+
// Do not add already present labels
543+
// Do not remove non-present labels
544+
ctx.pr(pr.id())
545+
.await
546+
.expect_added_labels(&["baz"])
547+
.expect_removed_labels(&["foo2"]);
548+
Ok(())
549+
})
550+
.await;
551+
}
552+
524553
#[sqlx::test]
525554
async fn unapprove(pool: sqlx::PgPool) {
526555
run_test(pool, async |ctx: &mut BorsTester| {

src/bors/handlers/trybuild.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ mod tests {
288288
use crate::github::CommitSha;
289289
use crate::github::api::client::HideCommentReason;
290290
use crate::tests::default_repo_name;
291-
use crate::tests::{BorsBuilder, Comment, GitHub, User, WorkflowEvent, run_test};
292291
use crate::tests::{BorsTester, Branch, Commit};
292+
use crate::tests::{Comment, GitHub, User, WorkflowEvent, run_test};
293293
use octocrab::params::checks::{CheckRunConclusion, CheckRunStatus};
294294

295295
#[sqlx::test]
@@ -839,30 +839,29 @@ try-job: Bar
839839

840840
#[sqlx::test]
841841
async fn try_build_failed_modify_labels(pool: sqlx::PgPool) {
842-
BorsBuilder::new(pool)
843-
.github(GitHub::default().with_default_config(
844-
r#"
842+
let gh = GitHub::default().with_default_config(
843+
r#"
845844
[labels]
846845
try_failed = ["+foo", "+bar", "-baz"]
847846
"#,
848-
))
849-
.run_test(async |ctx: &mut BorsTester| {
850-
ctx.post_comment("@bors try").await?;
851-
insta::assert_snapshot!(ctx.get_next_comment_text(()).await?, @r"
847+
);
848+
run_test((pool, gh), async |ctx: &mut BorsTester| {
849+
ctx.post_comment("@bors try").await?;
850+
insta::assert_snapshot!(ctx.get_next_comment_text(()).await?, @r"
852851
:hourglass: Trying commit pr-1-sha with merge merge-0-pr-1…
853852
854853
To cancel the try build, run the command `@bors try cancel`.
855854
");
856-
ctx.pr(()).await.expect_added_labels(&[]);
857-
ctx.workflow_full_failure(ctx.try_workflow()).await?;
858-
ctx.expect_comments((), 1).await;
859-
ctx.pr(())
860-
.await
861-
.expect_added_labels(&["foo", "bar"])
862-
.expect_removed_labels(&["baz"]);
863-
Ok(())
864-
})
865-
.await;
855+
ctx.pr(()).await.expect_added_labels(&[]);
856+
ctx.workflow_full_failure(ctx.try_workflow()).await?;
857+
ctx.expect_comments((), 1).await;
858+
ctx.pr(())
859+
.await
860+
.expect_added_labels(&["foo", "bar"])
861+
.expect_removed_labels(&["baz"]);
862+
Ok(())
863+
})
864+
.await;
866865
}
867866

868867
#[sqlx::test]

0 commit comments

Comments
 (0)