22#[ macro_use]
33mod test_util;
44
5- use futures:: FutureExt ;
65use poem:: http:: StatusCode ;
76use test_util:: TestContext ;
87
9- test ! [ negative_pr_number, |ctx: TestContext | async move {
10- let response = ctx. client( ) . get( "/api/v2/landings/-1" ) . send( ) . await ;
11- response. assert_status( StatusCode :: BAD_REQUEST ) ;
12- response
13- . assert_text( "Pull request number non-positive." )
14- . await ;
15- } ] ;
8+ #[ tokio:: test]
9+ async fn negative_pr_number ( ) {
10+ TestContext :: with ( async |ctx| {
11+ let response = ctx. client ( ) . get ( "/api/v2/landings/-1" ) . send ( ) . await ;
12+ response. assert_status ( StatusCode :: BAD_REQUEST ) ;
13+ response
14+ . assert_text ( "Pull request number non-positive." )
15+ . await ;
16+ } )
17+ . await ;
18+ }
1619
1720// https://github.com/molybdenumsoftware/pr-tracker/issues/241
1821// async fn bork_db(ctx: &mut db_context::DatabaseContext) {
@@ -26,63 +29,79 @@ test![negative_pr_number, |ctx: TestContext| async move {
2629// .await;
2730// }
2831//
29- // test![internal_landed_error, |mut ctx: TestContext| async move {
30- // bork_db(ctx.db_mut()).await;
31- // let response = ctx.client().get("/api/v2/landings/1").send().await;
32- // response.assert_status(StatusCode::SERVICE_UNAVAILABLE);
33- // response.assert_text("Error. Sorry.").await;
34- // }];
32+ // #[tokio::test]
33+ // async fn internal_landed_error() {
34+ // TestContext::with(async |mut ctx| {
35+ // bork_db(ctx.db_mut()).await;
36+ // let response = ctx.client().get("/api/v2/landings/1").send().await;
37+ // response.assert_status(StatusCode::SERVICE_UNAVAILABLE);
38+ // response.assert_text("Error. Sorry.").await;
39+ // })
40+ // .await;
41+ // }
3542
36- test ! [ pr_not_found, |ctx: TestContext | async move {
37- let response = ctx. client( ) . get( "/api/v2/landings/2134" ) . send( ) . await ;
38- response. assert_status( StatusCode :: NO_CONTENT ) ;
39- response. assert_text( "Pull request not found." ) . await ;
40- } ] ;
43+ #[ tokio:: test]
44+ async fn pr_not_found ( ) {
45+ TestContext :: with ( async |ctx| {
46+ let response = ctx. client ( ) . get ( "/api/v2/landings/2134" ) . send ( ) . await ;
47+ response. assert_status ( StatusCode :: NO_CONTENT ) ;
48+ response. assert_text ( "Pull request not found." ) . await ;
49+ } )
50+ . await ;
51+ }
4152
42- test ! [ pr_not_landed, |ctx: TestContext | async move {
43- let mut connection = ctx. db( ) . connection( ) . await . unwrap( ) ;
53+ #[ tokio:: test]
54+ async fn pr_not_landed ( ) {
55+ TestContext :: with ( async |ctx| {
56+ let mut connection = ctx. db ( ) . connection ( ) . await . unwrap ( ) ;
4457
45- pr_tracker_store:: Pr {
46- number: 123 . try_into( ) . unwrap( ) ,
47- commit: Some ( "deadbeef" . into( ) ) ,
48- }
49- . upsert( & mut connection)
50- . await
51- . unwrap( ) ;
58+ pr_tracker_store:: Pr {
59+ number : 123 . try_into ( ) . unwrap ( ) ,
60+ commit : Some ( "deadbeef" . into ( ) ) ,
61+ }
62+ . upsert ( & mut connection)
63+ . await
64+ . unwrap ( ) ;
5265
53- let response = ctx. client( ) . get( "/api/v2/landings/123" ) . send( ) . await ;
54- response. assert_status_is_ok( ) ;
55- response
56- . assert_json( pr_tracker_api:: LandedIn { branches: vec![ ] } )
57- . await ;
58- } ] ;
66+ let response = ctx. client ( ) . get ( "/api/v2/landings/123" ) . send ( ) . await ;
67+ response. assert_status_is_ok ( ) ;
68+ response
69+ . assert_json ( pr_tracker_api:: LandedIn { branches : vec ! [ ] } )
70+ . await ;
71+ } )
72+ . await ;
73+ }
5974
60- test ! [ pr_landed, |ctx: TestContext | async move {
61- let connection = & mut ctx. db( ) . connection( ) . await . unwrap( ) ;
75+ #[ tokio:: test]
76+ async fn pr_landed ( ) {
77+ TestContext :: with ( async |ctx| {
78+ let connection = & mut ctx. db ( ) . connection ( ) . await . unwrap ( ) ;
6279
63- let branch = pr_tracker_store:: Branch :: get_or_insert( connection, "nixos-unstable" )
64- . await
65- . unwrap( ) ;
80+ let branch = pr_tracker_store:: Branch :: get_or_insert ( connection, "nixos-unstable" )
81+ . await
82+ . unwrap ( ) ;
6683
67- let github_pr = pr_tracker_store:: Pr {
68- number: 2134 . try_into( ) . unwrap( ) ,
69- commit: Some ( "deadbeef" . into( ) ) ,
70- } ;
71- github_pr. clone( ) . upsert( connection) . await . unwrap( ) ;
84+ let github_pr = pr_tracker_store:: Pr {
85+ number : 2134 . try_into ( ) . unwrap ( ) ,
86+ commit : Some ( "deadbeef" . into ( ) ) ,
87+ } ;
88+ github_pr. clone ( ) . upsert ( connection) . await . unwrap ( ) ;
7289
73- let landing = pr_tracker_store:: Landing {
74- github_pr: github_pr. number,
75- branch_id: branch. id( ) ,
76- } ;
90+ let landing = pr_tracker_store:: Landing {
91+ github_pr : github_pr. number ,
92+ branch_id : branch. id ( ) ,
93+ } ;
7794
78- landing. upsert( connection) . await . unwrap( ) ;
95+ landing. upsert ( connection) . await . unwrap ( ) ;
7996
80- let response = ctx. client( ) . get( "/api/v2/landings/2134" ) . send( ) . await ;
81- response. assert_status_is_ok( ) ;
97+ let response = ctx. client ( ) . get ( "/api/v2/landings/2134" ) . send ( ) . await ;
98+ response. assert_status_is_ok ( ) ;
8299
83- response
84- . assert_json( pr_tracker_api:: LandedIn {
85- branches: vec![ pr_tracker_api:: Branch ( "nixos-unstable" . to_owned( ) ) ] ,
86- } )
87- . await ;
88- } ] ;
100+ response
101+ . assert_json ( pr_tracker_api:: LandedIn {
102+ branches : vec ! [ pr_tracker_api:: Branch ( "nixos-unstable" . to_owned( ) ) ] ,
103+ } )
104+ . await ;
105+ } )
106+ . await ;
107+ }
0 commit comments