@@ -6,7 +6,10 @@ use std::{
66use actix_web:: {
77 body:: MessageBody ,
88 dev:: { ServiceFactory , ServiceRequest , ServiceResponse } ,
9- web, App ,
9+ http:: StatusCode ,
10+ test,
11+ web:: { self , Bytes } ,
12+ App ,
1013} ;
1114use diesel:: { r2d2:: ConnectionManager , SqliteConnection } ;
1215use diesel_migrations:: MigrationHarness ;
@@ -130,11 +133,15 @@ fn standard_filter() -> insta::Settings {
130133 settings. add_filter ( "[0-9.]+[MG]B / [0-9.]+[MG]B" , "100MB / 300MB" ) ;
131134 // The loading and time can vary
132135 settings. add_filter ( "in [0-9]+ ms" , "in 10 ms" ) ;
136+
137+ // Debug messages have an additional ID
138+ settings. add_filter ( "\\ [DEBUG\\ ] \\ ([0-9]+\\ )" , "[DEBUG] (1)" ) ;
139+
133140 settings
134141}
135142
136143#[ test]
137- fn test_logfile ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
144+ async fn test_logfile ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
138145 let logfile = NamedTempFile :: new ( ) ?;
139146 let mut settings = Settings :: default ( ) ;
140147 settings. logging . file = Some ( logfile. path ( ) . to_string_lossy ( ) . to_string ( ) ) ;
@@ -163,7 +170,7 @@ fn test_logfile() -> Result<(), Box<dyn std::error::Error>> {
163170}
164171
165172#[ test]
166- fn test_logfile_debug ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
173+ async fn test_logfile_debug ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
167174 let logfile = NamedTempFile :: new ( ) ?;
168175 let mut settings = Settings :: default ( ) ;
169176 settings. logging . file = Some ( logfile. path ( ) . to_string_lossy ( ) . to_string ( ) ) ;
@@ -191,3 +198,21 @@ fn test_logfile_debug() -> Result<(), Box<dyn std::error::Error>> {
191198
192199 Ok ( ( ) )
193200}
201+
202+ #[ actix_web:: test]
203+ async fn serve_static_files ( ) {
204+ let db_dir = tempfile:: TempDir :: new ( ) . unwrap ( ) ;
205+ let cs = graphannis:: CorpusStorage :: with_auto_cache_size ( db_dir. path ( ) , false ) . unwrap ( ) ; // Import three corpora A,B and C
206+ import_test_corpora ( & cs) ;
207+
208+ let app = test:: init_service ( create_test_app ( web:: Data :: new ( cs) , Settings :: default ( ) ) ) . await ;
209+
210+ // Unauthorized user should not see any corpora
211+ let req = test:: TestRequest :: get ( )
212+ . uri ( "/v1/api-docs.html" )
213+ . to_request ( ) ;
214+ let resp = test:: call_service ( & app, req) . await ;
215+ assert_eq ! ( resp. status( ) , StatusCode :: OK ) ;
216+ let response_body: Bytes = test:: read_body ( resp) . await ;
217+ assert_eq ! ( false , response_body. is_empty( ) ) ;
218+ }
0 commit comments