@@ -66,13 +66,41 @@ fn get_sql_test_files() -> Vec<std::path::PathBuf> {
6666
6767use std:: fmt:: Write ;
6868
69+ #[ derive( Debug ) ]
70+ enum TestResult {
71+ Success ( String ) ,
72+ Skipped ( String ) ,
73+ }
74+
6975async fn run_sql_test (
7076 test_file : & std:: path:: Path ,
7177 app_data : & actix_web:: web:: Data < AppState > ,
7278 _echo_handle : & JoinHandle < ( ) > ,
7379 port : u16 ,
74- ) -> anyhow:: Result < String > {
80+ ) -> anyhow:: Result < TestResult > {
7581 let test_file_path = test_file. to_string_lossy ( ) . replace ( '\\' , "/" ) ;
82+ let stem = test_file. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
83+
84+ let db_url = std:: env:: var ( "DATABASE_URL" ) . unwrap_or_else ( |_| "sqlite::memory:" . to_string ( ) ) ;
85+ let db_type = if db_url. starts_with ( "postgres" ) {
86+ "postgres"
87+ } else if db_url. starts_with ( "mysql" ) || db_url. starts_with ( "mariadb" ) {
88+ "mysql"
89+ } else if db_url. starts_with ( "mssql" ) {
90+ "mssql"
91+ } else if db_url. starts_with ( "sqlite" ) {
92+ "sqlite"
93+ } else {
94+ panic ! ( "Unknown database type in DATABASE_URL: {}" , db_url) ;
95+ } ;
96+
97+ if stem. contains ( & format ! ( "_no{}" , db_type) ) {
98+ return Ok ( TestResult :: Skipped ( format ! (
99+ "Test skipped for database type: {}" ,
100+ db_type
101+ ) ) ) ;
102+ }
103+
76104 let mut query_params = "x=1" . to_string ( ) ;
77105 if test_file_path. contains ( "fetch" ) {
78106 write ! ( query_params, "&echo_port={port}" ) . unwrap ( ) ;
@@ -87,31 +115,30 @@ async fn run_sql_test(
87115 . map_err ( |e| anyhow:: anyhow!( "Test request timed out after 5 seconds: {}" , e) ) ??;
88116
89117 let body = test:: read_body ( resp) . await ;
90- Ok ( String :: from_utf8 ( body. to_vec ( ) ) ?)
118+ Ok ( TestResult :: Success ( String :: from_utf8 ( body. to_vec ( ) ) ?) )
91119}
92120
93- fn assert_test_result ( result : anyhow:: Result < String > , test_file : & std:: path:: Path ) {
94- let ( body, stem) = get_test_body_and_stem ( result, test_file) ;
95- assert_html_response ( & body, test_file) ;
96- let lowercase_body = body. to_lowercase ( ) ;
97-
98- if stem. starts_with ( "it_works" ) {
99- assert_it_works_tests ( & body, & lowercase_body, test_file) ;
100- } else if stem. starts_with ( "error_" ) {
101- assert_error_tests ( & stem, & lowercase_body, test_file) ;
121+ fn assert_test_result ( result : anyhow:: Result < TestResult > , test_file : & std:: path:: Path ) {
122+ match result {
123+ Ok ( TestResult :: Skipped ( reason) ) => {
124+ println ! ( "⏭️ Skipped {}: {}" , test_file. display( ) , reason) ;
125+ return ;
126+ }
127+ Ok ( TestResult :: Success ( body) ) => {
128+ assert_html_response ( & body, test_file) ;
129+ let lowercase_body = body. to_lowercase ( ) ;
130+ let stem = test_file. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
131+
132+ if stem. starts_with ( "it_works" ) {
133+ assert_it_works_tests ( & body, & lowercase_body, test_file) ;
134+ } else if stem. starts_with ( "error_" ) {
135+ assert_error_tests ( & stem, & lowercase_body, test_file) ;
136+ }
137+ }
138+ Err ( e) => panic ! ( "Failed to get response for {}: {}" , test_file. display( ) , e) ,
102139 }
103140}
104141
105- fn get_test_body_and_stem (
106- result : anyhow:: Result < String > ,
107- test_file : & std:: path:: Path ,
108- ) -> ( String , String ) {
109- let stem = test_file. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
110- let body = result
111- . unwrap_or_else ( |e| panic ! ( "Failed to get response for {}: {}" , test_file. display( ) , e) ) ;
112- ( body, stem)
113- }
114-
115142fn assert_html_response ( body : & str , test_file : & std:: path:: Path ) {
116143 assert ! (
117144 body. starts_with( "<!DOCTYPE html>" ) ,
0 commit comments