Skip to content

Commit f26f86e

Browse files
committed
test: add approve_wait_for_ci
1 parent b0c49b5 commit f26f86e

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

src/bors/handlers/review.rs

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub(super) async fn command_approve(
3737
};
3838

3939
if repo_state.config.load().wait_on_ci_approval {
40+
tracing::debug!("Checking CI status for PR {}", pr.number);
4041
// Get all the check suites for the PR.
4142
let checks = repo_state
4243
.client
@@ -273,18 +274,20 @@ async fn notify_of_pending_approval(
273274

274275
#[cfg(test)]
275276
mod tests {
277+
use tracing_test::traced_test;
278+
276279
use crate::{
277280
github::PullRequestNumber,
278281
tests::mocks::{
279-
default_pr_number, default_repo_name, run_test, BorsBuilder, BorsTester, Permissions,
280-
PullRequestChangeEvent, User, World,
282+
default_pr_number, default_repo_name, run_test, BorsBuilder, BorsTester, Branch,
283+
Permissions, PullRequestChangeEvent, User, World,
281284
},
282285
};
283286

284287
#[sqlx::test]
285288
async fn default_approve(pool: sqlx::PgPool) {
286289
BorsBuilder::new(pool)
287-
.world(create_world_with_approve_config())
290+
.world(create_world_with_immediate_approve_config())
288291
.run_test(|mut tester| async {
289292
tester.post_comment("@bors r+").await?;
290293
assert_eq!(
@@ -310,7 +313,7 @@ mod tests {
310313
#[sqlx::test]
311314
async fn approve_on_behalf(pool: sqlx::PgPool) {
312315
BorsBuilder::new(pool)
313-
.world(create_world_with_approve_config())
316+
.world(create_world_with_immediate_approve_config())
314317
.run_test(|mut tester| async {
315318
let approve_user = "user1";
316319
tester
@@ -351,7 +354,7 @@ mod tests {
351354
#[sqlx::test]
352355
async fn unapprove(pool: sqlx::PgPool) {
353356
BorsBuilder::new(pool)
354-
.world(create_world_with_approve_config())
357+
.world(create_world_with_immediate_approve_config())
355358
.run_test(|mut tester| async {
356359
tester.post_comment("@bors r+").await?;
357360
assert_eq!(
@@ -382,7 +385,7 @@ mod tests {
382385
#[sqlx::test]
383386
async fn unapprove_on_base_edited(pool: sqlx::PgPool) {
384387
BorsBuilder::new(pool)
385-
.world(create_world_with_approve_config())
388+
.world(create_world_with_immediate_approve_config())
386389
.run_test(|mut tester| async {
387390
tester.post_comment("@bors r+").await?;
388391
assert_eq!(
@@ -416,7 +419,7 @@ PR will need to be re-approved."#,
416419
#[sqlx::test]
417420
async fn edit_pr_do_nothing_when_base_not_edited(pool: sqlx::PgPool) {
418421
BorsBuilder::new(pool)
419-
.world(create_world_with_approve_config())
422+
.world(create_world_with_immediate_approve_config())
420423
.run_test(|mut tester| async {
421424
tester.post_comment("@bors r+").await?;
422425
assert_eq!(
@@ -468,7 +471,7 @@ PR will need to be re-approved."#,
468471
#[sqlx::test]
469472
async fn unapprove_on_push(pool: sqlx::PgPool) {
470473
BorsBuilder::new(pool)
471-
.world(create_world_with_approve_config())
474+
.world(create_world_with_immediate_approve_config())
472475
.run_test(|mut tester| async {
473476
tester.post_comment("@bors r+").await?;
474477
assert_eq!(
@@ -506,14 +509,47 @@ PR will need to be re-approved."#,
506509
.await;
507510
}
508511

509-
fn create_world_with_approve_config() -> World {
512+
#[traced_test]
513+
#[sqlx::test]
514+
async fn approve_wait_for_ci(pool: sqlx::PgPool) {
515+
BorsBuilder::new(pool)
516+
.world(create_world_with_ci_approved_config())
517+
.run_test(|mut tester| async {
518+
tester.post_comment("@bors r+").await?;
519+
assert_eq!(
520+
tester.get_comment().await?,
521+
":hourglass_flowing_sand: Waiting for CI checks to complete before approving..."
522+
);
523+
Ok(tester)
524+
})
525+
.await;
526+
}
527+
528+
fn create_world_with_immediate_approve_config() -> World {
529+
let world = World::default();
530+
world.default_repo().lock().set_config(
531+
r#"
532+
wait_on_ci_approval = false
533+
[labels]
534+
approve = ["+approved"]
535+
"#,
536+
);
537+
world
538+
}
539+
540+
fn create_world_with_ci_approved_config() -> World {
510541
let world = World::default();
511542
world.default_repo().lock().set_config(
512543
r#"
544+
wait_on_ci_approval = true
513545
[labels]
514546
approve = ["+approved"]
515547
"#,
516548
);
549+
world.default_repo().lock().branches.push(Branch::new(
550+
&format!("pr-{}", default_pr_number()),
551+
&format!("pr-{}-sha", default_pr_number()),
552+
));
517553
world
518554
}
519555

0 commit comments

Comments
 (0)