Skip to content

Commit df0e7cd

Browse files
authored
Merge pull request #402 from Kobzol/test-refactor
Refactor test suite
2 parents 376564c + 84be75a commit df0e7cd

23 files changed

+2157
-2179
lines changed

src/bors/handlers/help.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ You can use the following commands:
7979

8080
#[cfg(test)]
8181
mod tests {
82-
use crate::tests::mocks::run_test;
82+
use crate::tests::{BorsTester, run_test};
8383

8484
#[sqlx::test]
8585
async fn help_command(pool: sqlx::PgPool) {
86-
run_test(pool, async |tester| {
86+
run_test(pool, async |tester: &mut BorsTester| {
8787
tester.post_comment("@bors help").await?;
88-
insta::assert_snapshot!(tester.get_comment().await?, @r"
88+
insta::assert_snapshot!(tester.get_comment(()).await?, @r"
8989
You can use the following commands:
9090
9191
## PR management

src/bors/handlers/info.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ pub(super) async fn command_info(
7272

7373
#[cfg(test)]
7474
mod tests {
75-
use crate::tests::mocks::{WorkflowEvent, WorkflowRunData, run_test};
75+
use crate::tests::{BorsTester, WorkflowEvent, WorkflowRunData, run_test};
7676

7777
#[sqlx::test]
7878
async fn info_for_unapproved_pr(pool: sqlx::PgPool) {
79-
run_test(pool, async |tester| {
79+
run_test(pool, async |tester: &mut BorsTester| {
8080
tester.post_comment("@bors info").await?;
8181
insta::assert_snapshot!(
82-
tester.get_comment().await?,
82+
tester.get_comment(()).await?,
8383
@r"
8484
## Status of PR `1`
8585
- Not Approved
@@ -94,13 +94,13 @@ mod tests {
9494

9595
#[sqlx::test]
9696
async fn info_for_approved_pr(pool: sqlx::PgPool) {
97-
run_test(pool, async |tester| {
97+
run_test(pool, async |tester: &mut BorsTester| {
9898
tester.post_comment("@bors r+").await?;
99-
tester.expect_comments(1).await;
99+
tester.expect_comments((), 1).await;
100100

101101
tester.post_comment("@bors info").await?;
102102
insta::assert_snapshot!(
103-
tester.get_comment().await?,
103+
tester.get_comment(()).await?,
104104
@r"
105105
## Status of PR `1`
106106
- Approved by: `default-user`
@@ -115,15 +115,13 @@ mod tests {
115115

116116
#[sqlx::test]
117117
async fn info_for_pr_with_priority(pool: sqlx::PgPool) {
118-
run_test(pool, async |tester| {
118+
run_test(pool, async |tester: &mut BorsTester| {
119119
tester.post_comment("@bors p=5").await?;
120-
tester
121-
.wait_for_default_pr(|pr| pr.priority == Some(5))
122-
.await?;
120+
tester.wait_for_pr((), |pr| pr.priority == Some(5)).await?;
123121

124122
tester.post_comment("@bors info").await?;
125123
insta::assert_snapshot!(
126-
tester.get_comment().await?,
124+
tester.get_comment(()).await?,
127125
@r"
128126
## Status of PR `1`
129127
- Not Approved
@@ -138,13 +136,13 @@ mod tests {
138136

139137
#[sqlx::test]
140138
async fn info_for_pr_with_try_build(pool: sqlx::PgPool) {
141-
run_test(pool, async |tester| {
139+
run_test(pool, async |tester: &mut BorsTester| {
142140
tester.post_comment("@bors try").await?;
143-
tester.expect_comments(1).await;
141+
tester.expect_comments((), 1).await;
144142

145143
tester.post_comment("@bors info").await?;
146144
insta::assert_snapshot!(
147-
tester.get_comment().await?,
145+
tester.get_comment(()).await?,
148146
@r"
149147
## Status of PR `1`
150148
- Not Approved
@@ -160,22 +158,22 @@ mod tests {
160158

161159
#[sqlx::test]
162160
async fn info_for_pr_with_everything(pool: sqlx::PgPool) {
163-
run_test(pool, async |tester| {
161+
run_test(pool, async |tester: &mut BorsTester| {
164162
tester.post_comment("@bors r+ p=10").await?;
165-
tester.expect_comments(1).await;
163+
tester.expect_comments((), 1).await;
166164

167165
tester.post_comment("@bors try").await?;
168-
tester.expect_comments(1).await;
166+
tester.expect_comments((), 1).await;
169167

170168
tester
171169
.workflow_event(WorkflowEvent::started(WorkflowRunData::from(
172-
tester.try_branch(),
170+
tester.try_branch().await,
173171
)))
174172
.await?;
175173

176174
tester.post_comment("@bors info").await?;
177175
insta::assert_snapshot!(
178-
tester.get_comment().await?,
176+
tester.get_comment(()).await?,
179177
@r"
180178
## Status of PR `1`
181179
- Approved by: `default-user`

src/bors/handlers/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,11 @@ async fn unapprove_pr(
640640

641641
#[cfg(test)]
642642
mod tests {
643-
use crate::tests::mocks::{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) {
647-
run_test(pool, async |tester| {
647+
run_test(pool, async |tester: &mut BorsTester| {
648648
tester
649649
.post_comment(Comment::from("@bors ping").with_author(User::bors_bot()))
650650
.await?;
@@ -656,8 +656,10 @@ mod tests {
656656

657657
#[sqlx::test]
658658
async fn do_not_load_pr_on_unrelated_comment(pool: sqlx::PgPool) {
659-
run_test(pool, async |tester| {
660-
tester.default_repo().lock().pull_request_error = true;
659+
run_test(pool, async |tester: &mut BorsTester| {
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
})
@@ -666,9 +668,9 @@ mod tests {
666668

667669
#[sqlx::test]
668670
async fn unknown_command(pool: sqlx::PgPool) {
669-
run_test(pool, async |tester| {
671+
run_test(pool, async |tester: &mut BorsTester| {
670672
tester.post_comment(Comment::from("@bors foo")).await?;
671-
insta::assert_snapshot!(tester.get_comment().await?, @r#"Unknown command "foo". Run `@bors help` to see available commands."#);
673+
insta::assert_snapshot!(tester.get_comment(()).await?, @r#"Unknown command "foo". Run `@bors help` to see available commands."#);
672674
Ok(())
673675
})
674676
.await;

src/bors/handlers/ping.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ pub(super) async fn command_ping(
1616

1717
#[cfg(test)]
1818
mod tests {
19-
use crate::tests::mocks::run_test;
19+
use crate::tests::{BorsTester, run_test};
2020

2121
#[sqlx::test]
2222
async fn ping_command(pool: sqlx::PgPool) {
23-
run_test(pool, async |tester| {
23+
run_test(pool, async |tester: &mut BorsTester| {
2424
tester.post_comment("@bors ping").await?;
25-
assert_eq!(tester.get_comment().await?, "Pong 🏓!");
25+
assert_eq!(tester.get_comment(()).await?, "Pong 🏓!");
2626
Ok(())
2727
})
2828
.await;

0 commit comments

Comments
 (0)