@@ -100,8 +100,7 @@ mod actix_tests {
100100 use actix_web:: {
101101 ResponseError ,
102102 body:: to_bytes,
103- http:: header:: { RETRY_AFTER , WWW_AUTHENTICATE } ,
104- rt:: System
103+ http:: header:: { RETRY_AFTER , WWW_AUTHENTICATE }
105104 } ;
106105
107106 use crate :: { AppCode , AppError , AppErrorKind , ErrorResponse } ;
@@ -112,8 +111,8 @@ mod actix_tests {
112111 assert_eq ! ( e. status_code( ) . as_u16( ) , 422 ) ;
113112 }
114113
115- #[ test]
116- fn error_response_sets_body_and_headers ( ) {
114+ #[ actix_web :: test] // ← вот это
115+ async fn error_response_sets_body_and_headers ( ) -> Result < ( ) , Box < dyn std :: error :: Error > > {
117116 let err = AppError :: unauthorized ( "no token" )
118117 . with_retry_after_secs ( 7 )
119118 . with_www_authenticate ( "Bearer" ) ;
@@ -122,14 +121,20 @@ mod actix_tests {
122121 assert_eq ! ( resp. status( ) . as_u16( ) , 401 ) ;
123122
124123 let headers = resp. headers ( ) . clone ( ) ;
125- assert_eq ! ( headers. get( RETRY_AFTER ) . unwrap( ) , "7" ) ;
126- assert_eq ! ( headers. get( WWW_AUTHENTICATE ) . unwrap( ) , "Bearer" ) ;
124+ assert_eq ! (
125+ headers. get( RETRY_AFTER ) . and_then( |v| v. to_str( ) . ok( ) ) ,
126+ Some ( "7" )
127+ ) ;
128+ assert_eq ! (
129+ headers. get( WWW_AUTHENTICATE ) . and_then( |v| v. to_str( ) . ok( ) ) ,
130+ Some ( "Bearer" )
131+ ) ;
127132
128- let bytes = System :: new ( )
129- . block_on ( async { to_bytes ( resp. into_body ( ) , usize:: MAX ) . await . expect ( "body" ) } ) ;
130- let body: ErrorResponse = serde_json:: from_slice ( & bytes) . expect ( "json body" ) ;
133+ let bytes = to_bytes ( resp. into_body ( ) ) . await ?;
134+ let body: ErrorResponse = serde_json:: from_slice ( & bytes) ?;
131135 assert_eq ! ( body. status, 401 ) ;
132136 assert ! ( matches!( body. code, AppCode :: Unauthorized ) ) ;
133137 assert_eq ! ( body. message, "no token" ) ;
138+ Ok ( ( ) )
134139 }
135140}
0 commit comments