33use super :: model:: {
44 CommonImporter , Importer , ImporterConfiguration , ImporterData , SbomImporter , State ,
55} ;
6+ use actix_http:: { Request , body:: BoxBody } ;
67use actix_web:: {
78 App ,
9+ dev:: { Service , ServiceResponse } ,
810 http:: { StatusCode , header} ,
911 test as actix,
1012} ;
@@ -52,11 +54,11 @@ fn mock_importer(result: &Importer, source: impl Into<String>) -> Importer {
5254 }
5355}
5456
55- # [ test_context ( TrustifyContext , skip_teardown ) ]
56- # [ test ( actix_web :: test ) ]
57- async fn default ( ctx : TrustifyContext ) {
58- let db = ctx. db ;
59- let app = actix:: init_service (
57+ async fn app (
58+ ctx : & TrustifyContext ,
59+ ) -> impl Service < Request , Response = ServiceResponse < BoxBody > , Error = actix_web :: Error > {
60+ let db = ctx. db . clone ( ) ;
61+ actix:: init_service (
6062 App :: new ( )
6163 . into_utoipa_app ( )
6264 . add_test_authorizer ( )
@@ -66,7 +68,13 @@ async fn default(ctx: TrustifyContext) {
6668 )
6769 . into_app ( ) ,
6870 )
69- . await ;
71+ . await
72+ }
73+
74+ #[ test_context( TrustifyContext , skip_teardown) ]
75+ #[ test( actix_web:: test) ]
76+ async fn default ( ctx : TrustifyContext ) {
77+ let app = app ( & ctx) . await ;
7078
7179 // create one
7280
@@ -150,18 +158,7 @@ async fn default(ctx: TrustifyContext) {
150158#[ test_context( TrustifyContext , skip_teardown) ]
151159#[ test( actix_web:: test) ]
152160async fn oplock ( ctx : TrustifyContext ) {
153- let db = ctx. db ;
154- let app = actix:: init_service (
155- App :: new ( )
156- . into_utoipa_app ( )
157- . add_test_authorizer ( )
158- . service (
159- utoipa_actix_web:: scope ( "/api" )
160- . configure ( |svc| super :: endpoints:: configure ( svc, db) ) ,
161- )
162- . into_app ( ) ,
163- )
164- . await ;
161+ let app = app ( & ctx) . await ;
165162
166163 // create one
167164
@@ -307,18 +304,7 @@ async fn oplock(ctx: TrustifyContext) {
307304#[ test_context( TrustifyContext , skip_teardown) ]
308305#[ test( actix_web:: test) ]
309306async fn patch ( ctx : TrustifyContext ) {
310- let db = ctx. db ;
311- let app = actix:: init_service (
312- App :: new ( )
313- . into_utoipa_app ( )
314- . add_test_authorizer ( )
315- . service (
316- utoipa_actix_web:: scope ( "/api" )
317- . configure ( |svc| super :: endpoints:: configure ( svc, db) ) ,
318- )
319- . into_app ( ) ,
320- )
321- . await ;
307+ let app = app ( & ctx) . await ;
322308
323309 // create one
324310
0 commit comments