@@ -3,7 +3,8 @@ use std::sync::Arc;
33use biome_deserialize:: { Merge , StringSet } ;
44use pgt_analyse:: RuleCategories ;
55use pgt_configuration:: {
6- PartialConfiguration , database:: PartialDatabaseConfiguration , files:: PartialFilesConfiguration ,
6+ PartialConfiguration , PartialTypecheckConfiguration , database:: PartialDatabaseConfiguration ,
7+ files:: PartialFilesConfiguration ,
78} ;
89use pgt_diagnostics:: Diagnostic ;
910use pgt_fs:: PgTPath ;
@@ -331,3 +332,113 @@ async fn test_positional_params(test_db: PgPool) {
331332
332333 assert_eq ! ( diagnostics. len( ) , 0 , "Expected no diagnostic" ) ;
333334}
335+
336+ #[ sqlx:: test( migrator = "pgt_test_utils::MIGRATIONS" ) ]
337+ async fn test_search_path_configuration ( test_db : PgPool ) {
338+ // Setup test schemas and functions
339+ let setup_sql = r#"
340+ create schema if not exists private;
341+
342+ create or replace function private.get_user_id() returns integer as $$
343+ select 1;
344+ $$ language sql;
345+ "# ;
346+ test_db. execute ( setup_sql) . await . expect ( "setup sql failed" ) ;
347+
348+ let path_glob = PgTPath :: new ( "test_glob.sql" ) ;
349+ let file_content = r#"
350+ select get_user_id(); -- on private schema
351+ "# ;
352+
353+ // first check that the we get a valid typecheck
354+ let mut glob_conf = PartialConfiguration :: init ( ) ;
355+ glob_conf. merge_with ( PartialConfiguration {
356+ db : Some ( PartialDatabaseConfiguration {
357+ database : Some (
358+ test_db
359+ . connect_options ( )
360+ . get_database ( )
361+ . unwrap ( )
362+ . to_string ( ) ,
363+ ) ,
364+ ..Default :: default ( )
365+ } ) ,
366+ ..Default :: default ( )
367+ } ) ;
368+
369+ // without glob
370+ {
371+ let workspace =
372+ get_test_workspace ( Some ( glob_conf. clone ( ) ) ) . expect ( "Unable to create test workspace" ) ;
373+
374+ workspace
375+ . open_file ( OpenFileParams {
376+ path : path_glob. clone ( ) ,
377+ content : file_content. into ( ) ,
378+ version : 1 ,
379+ } )
380+ . expect ( "Unable to open test file" ) ;
381+
382+ let diagnostics_glob = workspace
383+ . pull_diagnostics ( crate :: workspace:: PullDiagnosticsParams {
384+ path : path_glob. clone ( ) ,
385+ categories : RuleCategories :: all ( ) ,
386+ max_diagnostics : 100 ,
387+ only : vec ! [ ] ,
388+ skip : vec ! [ ] ,
389+ } )
390+ . expect ( "Unable to pull diagnostics" )
391+ . diagnostics ;
392+
393+ assert_eq ! (
394+ diagnostics_glob. len( ) ,
395+ 1 ,
396+ "get_user_id() should not be found in search_path"
397+ ) ;
398+
399+ // yep, type error!
400+ assert_eq ! (
401+ diagnostics_glob[ 0 ] . category( ) . map( |c| c. name( ) ) ,
402+ Some ( "typecheck" )
403+ ) ;
404+ }
405+
406+ // adding the glob
407+ glob_conf. merge_with ( PartialConfiguration {
408+ typecheck : Some ( PartialTypecheckConfiguration {
409+ // Adding glob pattern to match the "private" schema
410+ search_path : Some ( StringSet :: from_iter ( vec ! [ "pr*" . to_string( ) ] ) ) ,
411+ } ) ,
412+ ..Default :: default ( )
413+ } ) ; // checking with the pattern should yield no diagnostics
414+
415+ {
416+ let workspace =
417+ get_test_workspace ( Some ( glob_conf. clone ( ) ) ) . expect ( "Unable to create test workspace" ) ;
418+
419+ workspace
420+ . open_file ( OpenFileParams {
421+ path : path_glob. clone ( ) ,
422+ content : file_content. into ( ) ,
423+ version : 1 ,
424+ } )
425+ . expect ( "Unable to open test file" ) ;
426+
427+ let diagnostics_glob = workspace
428+ . pull_diagnostics ( crate :: workspace:: PullDiagnosticsParams {
429+ path : path_glob. clone ( ) ,
430+ categories : RuleCategories :: all ( ) ,
431+ max_diagnostics : 100 ,
432+ only : vec ! [ ] ,
433+ skip : vec ! [ ] ,
434+ } )
435+ . expect ( "Unable to pull diagnostics" )
436+ . diagnostics ;
437+
438+ assert_eq ! (
439+ diagnostics_glob. len( ) ,
440+ 0 ,
441+ "Glob pattern should put private schema in search path"
442+ ) ;
443+ }
444+ }
0 commit comments