@@ -362,10 +362,8 @@ fn for_file_optimized(run_config: &RunConfig, file_path: &str) -> RunResult {
362362mod tests {
363363 use tempfile:: tempdir;
364364
365- use crate :: { common_test, ownership:: mapper:: Source } ;
366- use ignore:: { DirEntry , WalkBuilder , WalkParallel , WalkState } ;
367-
368365 use super :: * ;
366+ use crate :: { common_test, ownership:: mapper:: Source } ;
369367
370368 #[ test]
371369 fn test_version ( ) {
@@ -421,42 +419,33 @@ mod tests {
421419
422420 #[ test]
423421 fn test_teams_for_files_from_codeowners ( ) {
424- let project_root = Path :: new ( "/Users/perryhertler/workspace/zenpayroll" ) ;
425- let codeowners_file_path = project_root. join ( ".github/CODEOWNERS" ) ;
426- let config_path = project_root. join ( "config/code_ownership.yml" ) ;
427- let run_config = RunConfig {
428- project_root : project_root. to_path_buf ( ) ,
429- codeowners_file_path : codeowners_file_path. to_path_buf ( ) ,
430- config_path : config_path. to_path_buf ( ) ,
431- no_cache : false ,
432- } ;
433-
434- // Collect all files in packs and frontend directories recursively
435- let mut file_paths = Vec :: new ( ) ;
436- for dir in [ "packs" , "frontend" ] {
437- let dir_path = project_root. join ( dir) ;
438- if dir_path. exists ( ) && dir_path. is_dir ( ) {
439- for entry in WalkBuilder :: new ( & dir_path)
440- . filter_entry ( |e| {
441- let name = e. file_name ( ) . to_str ( ) . unwrap_or ( "" ) ;
442- !( name == "node_modules" || name == "dist" || name == ".git" )
443- } )
444- . build ( )
445- . filter_map ( |e| e. ok ( ) )
446- . filter ( |e| e. file_type ( ) . map ( |t| t. is_file ( ) ) . unwrap_or ( false ) )
447- . filter_map ( |e| e. path ( ) . strip_prefix ( project_root) . ok ( ) . map ( |p| p. to_string_lossy ( ) . to_string ( ) ) )
448- {
449- file_paths. push ( entry) ;
450- }
451- }
452- }
453-
454- let start_time = std:: time:: Instant :: now ( ) ;
455- let teams = teams_for_files_from_codeowners ( & run_config, & file_paths) . unwrap ( ) ;
456- let end_time = std:: time:: Instant :: now ( ) ;
457- println ! ( "Time taken: {:?}" , end_time. duration_since( start_time) ) ;
458- println ! ( "Teams: {:?}" , teams) ;
459- assert_eq ! ( teams. len( ) , 1 ) ;
460-
422+ let project_root = Path :: new ( "tests/fixtures/valid_project" ) ;
423+ let file_paths = [
424+ "javascript/packages/items/item.ts" ,
425+ "config/teams/payroll.yml" ,
426+ "ruby/app/models/bank_account.rb" ,
427+ "made/up/file.rb" ,
428+ "ruby/ignored_files/git_ignored.rb" ,
429+ ] ;
430+ let run_config = RunConfig {
431+ project_root : project_root. to_path_buf ( ) ,
432+ codeowners_file_path : project_root. join ( ".github/CODEOWNERS" ) . to_path_buf ( ) ,
433+ config_path : project_root. join ( "config/code_ownership.yml" ) . to_path_buf ( ) ,
434+ no_cache : false ,
435+ } ;
436+ let teams =
437+ teams_for_files_from_codeowners ( & run_config, & file_paths. iter ( ) . map ( |s| s. to_string ( ) ) . collect :: < Vec < String > > ( ) ) . unwrap ( ) ;
438+ assert_eq ! ( teams. len( ) , 3 ) ;
439+ assert_eq ! (
440+ teams. get( "javascript/packages/items/item.ts" ) . map( |t| t. name. as_str( ) ) ,
441+ Some ( "Payroll" )
442+ ) ;
443+ assert_eq ! ( teams. get( "config/teams/payroll.yml" ) . map( |t| t. name. as_str( ) ) , Some ( "Payroll" ) ) ;
444+ assert_eq ! (
445+ teams. get( "ruby/app/models/bank_account.rb" ) . map( |t| t. name. as_str( ) ) ,
446+ Some ( "Payments" )
447+ ) ;
448+ assert_eq ! ( teams. get( "made/up/file.rb" ) . map( |t| t. name. as_str( ) ) , None ) ;
449+ assert_eq ! ( teams. get( "ruby/ignored_files/git_ignored.rb" ) . map( |t| t. name. as_str( ) ) , None ) ;
461450 }
462451}
0 commit comments