1818use std:: { io:: Read , time:: Duration } ;
1919
2020use assert_cmd:: Command ;
21- use datafusion_dft:: test_utils:: fixture:: { TestFixture , TestFlightSqlServiceImpl } ;
21+ use datafusion_app:: local:: ExecutionContext ;
22+ use datafusion_dft:: {
23+ execution:: AppExecution ,
24+ server:: flightsql:: service:: FlightSqlServiceImpl ,
25+ test_utils:: fixture:: { TestFixture , TestFlightSqlServiceImpl } ,
26+ } ;
2227
2328use crate :: {
2429 cli_cases:: { contains_str, sql_in_file} ,
@@ -603,24 +608,34 @@ async fn test_output_parquet() {
603608
604609 let cloned_path = path. clone ( ) ;
605610
606- let sql = "SELECT 1" . to_string ( ) ;
607- Command :: cargo_bin ( "dft" )
608- . unwrap ( )
609- . arg ( "-c" )
610- . arg ( sql. clone ( ) )
611- . arg ( "-o" )
612- . arg ( cloned_path)
613- . assert ( )
614- . success ( ) ;
611+ tokio:: task:: spawn_blocking ( || {
612+ let sql = "SELECT 1" . to_string ( ) ;
613+ Command :: cargo_bin ( "dft" )
614+ . unwrap ( )
615+ . arg ( "-c" )
616+ . arg ( sql. clone ( ) )
617+ . arg ( "--flightsql" )
618+ . arg ( "-o" )
619+ . arg ( cloned_path)
620+ . timeout ( Duration :: from_secs ( 5 ) )
621+ . assert ( )
622+ . success ( ) ;
623+ } )
624+ . await
625+ . unwrap ( ) ;
615626
616627 let read_sql = format ! ( "SELECT * FROM '{}'" , path. to_str( ) . unwrap( ) ) ;
617628
618- let assert = Command :: cargo_bin ( "dft" )
619- . unwrap ( )
620- . arg ( "-c" )
621- . arg ( read_sql)
622- . assert ( )
623- . success ( ) ;
629+ let assert = tokio:: task:: spawn_blocking ( || {
630+ Command :: cargo_bin ( "dft" )
631+ . unwrap ( )
632+ . arg ( "-c" )
633+ . arg ( read_sql)
634+ . assert ( )
635+ . success ( )
636+ } )
637+ . await
638+ . unwrap ( ) ;
624639
625640 let expected = r#"
626641+----------+
@@ -633,3 +648,65 @@ async fn test_output_parquet() {
633648
634649 fixture. shutdown_and_wait ( ) . await ;
635650}
651+
652+ #[ tokio:: test]
653+ async fn test_flightsql_query_command ( ) {
654+ let test_server = TestFlightSqlServiceImpl :: new ( ) ;
655+ let fixture = TestFixture :: new ( test_server. service ( ) , "127.0.0.1:50051" ) . await ;
656+
657+ let assert = tokio:: task:: spawn_blocking ( || {
658+ let sql = "SELECT 1" . to_string ( ) ;
659+ Command :: cargo_bin ( "dft" )
660+ . unwrap ( )
661+ . arg ( "flightsql" )
662+ . arg ( "statement-query" )
663+ . arg ( sql. clone ( ) )
664+ . timeout ( Duration :: from_secs ( 5 ) )
665+ . assert ( )
666+ . success ( )
667+ } )
668+ . await
669+ . unwrap ( ) ;
670+
671+ let expected = r#"
672+ +----------+
673+ | Int64(1) |
674+ +----------+
675+ | 1 |
676+ +----------+"# ;
677+
678+ assert. stdout ( contains_str ( expected) ) ;
679+
680+ fixture. shutdown_and_wait ( ) . await ;
681+ }
682+
683+ #[ tokio:: test]
684+ async fn test_flightsql_get_catalogs ( ) {
685+ let ctx = ExecutionContext :: default ( ) ;
686+ let exec = AppExecution :: new ( ctx) ;
687+ let test_server = FlightSqlServiceImpl :: new ( exec) ;
688+ let fixture = TestFixture :: new ( test_server. service ( ) , "127.0.0.1:50051" ) . await ;
689+
690+ let assert = tokio:: task:: spawn_blocking ( || {
691+ Command :: cargo_bin ( "dft" )
692+ . unwrap ( )
693+ . arg ( "flightsql" )
694+ . arg ( "get-catalogs" )
695+ . timeout ( Duration :: from_secs ( 5 ) )
696+ . assert ( )
697+ . success ( )
698+ } )
699+ . await
700+ . unwrap ( ) ;
701+
702+ let expected = r#"
703+ +---------------+
704+ | table_catalog |
705+ +---------------+
706+ | datafusion |
707+ +---------------+"# ;
708+
709+ assert. stdout ( contains_str ( expected) ) ;
710+
711+ fixture. shutdown_and_wait ( ) . await ;
712+ }
0 commit comments