File tree Expand file tree Collapse file tree 9 files changed +41
-39
lines changed Expand file tree Collapse file tree 9 files changed +41
-39
lines changed Original file line number Diff line number Diff line change 1
- use anyhow:: Context ;
2
1
use std:: sync:: Arc ;
2
+
3
+ use anyhow:: Context ;
3
4
use tracing:: Instrument ;
4
5
5
6
use crate :: bors:: command:: { BorsCommand , CommandParseError } ;
@@ -273,25 +274,17 @@ fn is_bors_observed_branch(branch: &str) -> bool {
273
274
274
275
#[ cfg( test) ]
275
276
mod tests {
276
- use crate :: tests:: event:: { comment, default_pr_number} ;
277
- use crate :: tests:: state:: { test_bot_user, ClientBuilder } ;
277
+ use crate :: tests:: mocks:: { run_test, Comment , User } ;
278
278
279
279
#[ sqlx:: test]
280
- async fn test_ignore_bot_comment ( pool : sqlx:: PgPool ) {
281
- let state = ClientBuilder :: default ( ) . pool ( pool) . create_state ( ) . await ;
282
- state
283
- . comment ( comment ( "@bors ping" ) . author ( test_bot_user ( ) ) . create ( ) )
284
- . await ;
285
- state. client ( ) . check_comments ( default_pr_number ( ) , & [ ] ) ;
280
+ async fn ignore_bot_comment ( pool : sqlx:: PgPool ) {
281
+ run_test ( pool, |mut tester| async {
282
+ tester
283
+ . post_comment ( Comment :: from ( "@bors ping" ) . with_author ( User :: bors_bot ( ) ) )
284
+ . await ;
285
+ // Returning here will make sure that no comments were received
286
+ Ok ( tester)
287
+ } )
288
+ . await ;
286
289
}
287
-
288
- // #[sqlx::test]
289
- // async fn test_do_not_comment_when_pr_fetch_fails(pool: sqlx::PgPool) {
290
- // let state = ClientBuilder::default().pool(pool).create_state().await;
291
- // state
292
- // .client()
293
- // .set_get_pr_fn(|_| Err(anyhow::anyhow!("Foo")));
294
- // state.comment(comment("foo").create()).await;
295
- // state.client().check_comments(default_pr_number(), &[]);
296
- // }
297
290
}
Original file line number Diff line number Diff line change @@ -65,10 +65,6 @@ impl From<CommentBuilder> for PullRequestComment {
65
65
}
66
66
}
67
67
68
- pub fn comment ( text : & str ) -> CommentBuilder {
69
- CommentBuilder :: default ( ) . text ( text. to_string ( ) )
70
- }
71
-
72
68
pub fn suite_success ( ) -> CheckSuite {
73
69
CheckSuite {
74
70
status : CheckSuiteStatus :: Success ,
Original file line number Diff line number Diff line change
1
+ use crate :: tests:: mocks:: User ;
1
2
use serde:: Serialize ;
2
3
use url:: Url ;
3
4
use wiremock:: {
@@ -53,7 +54,7 @@ impl Default for App {
53
54
owner : GitHubUser :: default ( ) ,
54
55
name : "bors" . to_string ( ) ,
55
56
// same as bors user html_url
56
- html_url : "https://test-bors.bot.com" . parse ( ) . unwrap ( ) ,
57
+ html_url : GitHubUser :: from ( User :: bors_bot ( ) ) . html_url ,
57
58
external_url : "https://test-bors.bot.com" . parse ( ) . unwrap ( ) ,
58
59
permissions : Permissions { } ,
59
60
events : vec ! [ "*" . to_string( ) ] ,
Original file line number Diff line number Diff line change @@ -116,13 +116,8 @@ impl BorsTester {
116
116
. content
117
117
}
118
118
119
- pub async fn post_comment ( & mut self , content : & str ) {
120
- self . webhook_comment ( Comment :: new (
121
- Repo :: default ( ) . name ,
122
- default_pr_number ( ) ,
123
- content,
124
- ) )
125
- . await ;
119
+ pub async fn post_comment < C : Into < Comment > > ( & mut self , comment : C ) {
120
+ self . webhook_comment ( comment. into ( ) ) . await ;
126
121
}
127
122
128
123
async fn webhook_comment ( & mut self , comment : Comment ) {
Original file line number Diff line number Diff line change @@ -6,8 +6,10 @@ use serde::Serialize;
6
6
use url:: Url ;
7
7
8
8
use crate :: github:: GithubRepoName ;
9
+ use crate :: tests:: event:: default_pr_number;
9
10
use crate :: tests:: mocks:: repository:: GitHubRepository ;
10
11
use crate :: tests:: mocks:: user:: { GitHubUser , User } ;
12
+ use crate :: tests:: mocks:: Repo ;
11
13
12
14
#[ derive( Clone , Debug ) ]
13
15
pub struct Comment {
@@ -32,6 +34,12 @@ impl Comment {
32
34
}
33
35
}
34
36
37
+ impl < ' a > From < & ' a str > for Comment {
38
+ fn from ( value : & ' a str ) -> Self {
39
+ Comment :: new ( Repo :: default ( ) . name , default_pr_number ( ) , value)
40
+ }
41
+ }
42
+
35
43
// Copied from octocrab, since its version if #[non_exhaustive]
36
44
#[ derive( Serialize ) ]
37
45
pub struct GitHubIssueCommentEventPayload {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ use crate::tests::mocks::permissions::TeamApiMockServer;
9
9
use crate :: TeamApiClient ;
10
10
11
11
pub use bors:: run_test;
12
+ pub use comment:: Comment ;
12
13
pub use repository:: Repo ;
13
14
pub use user:: User ;
14
15
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ use super::{
10
10
Repo , User ,
11
11
} ;
12
12
13
+ pub fn default_pr_number ( ) -> u64 {
14
+ 1
15
+ }
16
+
13
17
pub async fn mock_pull_requests (
14
18
repo : & Repo ,
15
19
comments_tx : Sender < Comment > ,
@@ -35,7 +39,7 @@ pub async fn mock_pull_requests(
35
39
let comment_payload: CommentCreatePayload = req. body_json ( ) . unwrap ( ) ;
36
40
let comment: Comment =
37
41
Comment :: new ( repo_name. clone ( ) , pr_number, & comment_payload. body )
38
- . with_author ( User :: new ( 1002 , "bors" ) ) ;
42
+ . with_author ( User :: bors_bot ( ) ) ;
39
43
40
44
// We cannot use `tx.blocking_send()`, because this function is actually called
41
45
// from within an async task, but it is not async, so we also cannot use
@@ -105,10 +109,6 @@ struct Base {
105
109
sha : String ,
106
110
}
107
111
108
- fn default_pr_number ( ) -> u64 {
109
- 1
110
- }
111
-
112
112
#[ derive( Deserialize ) ]
113
113
struct CommentCreatePayload {
114
114
body : String ,
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ timeout = 3600
64
64
}
65
65
}
66
66
67
- fn default_repo_name ( ) -> GithubRepoName {
67
+ pub fn default_repo_name ( ) -> GithubRepoName {
68
68
GithubRepoName :: new ( "rust-lang" , "borstest" )
69
69
}
70
70
Original file line number Diff line number Diff line change @@ -8,6 +8,14 @@ pub struct User {
8
8
}
9
9
10
10
impl User {
11
+ pub fn default_user ( ) -> Self {
12
+ Self :: new ( 101 , "default-user" )
13
+ }
14
+
15
+ pub fn bors_bot ( ) -> Self {
16
+ Self :: new ( 102 , "bors-bot" )
17
+ }
18
+
11
19
pub fn new ( id : u64 , name : & str ) -> Self {
12
20
Self {
13
21
github_id : id,
@@ -18,7 +26,7 @@ impl User {
18
26
19
27
impl Default for User {
20
28
fn default ( ) -> Self {
21
- Self :: new ( 101 , "default-user" )
29
+ Self :: default_user ( )
22
30
}
23
31
}
24
32
@@ -30,7 +38,7 @@ pub struct GitHubUser {
30
38
avatar_url : Url ,
31
39
gravatar_id : String ,
32
40
url : Url ,
33
- html_url : Url ,
41
+ pub html_url : Url ,
34
42
followers_url : Url ,
35
43
following_url : Url ,
36
44
gists_url : Url ,
You can’t perform that action at this time.
0 commit comments