@@ -242,119 +242,10 @@ impl Runner {
242242
243243#[ cfg( test) ]
244244mod tests {
245- use std:: path:: Path ;
246- use tempfile:: tempdir;
247-
248245 use super :: * ;
249- use crate :: { common_test, ownership:: mapper:: Source } ;
250246
251247 #[ test]
252248 fn test_version ( ) {
253249 assert_eq ! ( version( ) , env!( "CARGO_PKG_VERSION" ) . to_string( ) ) ;
254250 }
255- fn write_file ( temp_dir : & Path , file_path : & str , content : & str ) {
256- let file_path = temp_dir. join ( file_path) ;
257- let _ = std:: fs:: create_dir_all ( file_path. parent ( ) . unwrap ( ) ) ;
258- std:: fs:: write ( file_path, content) . unwrap ( ) ;
259- }
260-
261- #[ test]
262- fn test_file_owners_for_file ( ) {
263- let temp_dir = tempdir ( ) . unwrap ( ) ;
264- write_file (
265- temp_dir. path ( ) ,
266- "config/code_ownership.yml" ,
267- common_test:: tests:: DEFAULT_CODE_OWNERSHIP_YML ,
268- ) ;
269- [ "a" , "b" , "c" ] . iter ( ) . for_each ( |name| {
270- let team_yml = format ! ( "name: {}\n github:\n team: \" @{}\" \n members:\n - {}member\n " , name, name, name) ;
271- write_file ( temp_dir. path ( ) , & format ! ( "config/teams/{}.yml" , name) , & team_yml) ;
272- } ) ;
273- write_file (
274- temp_dir. path ( ) ,
275- "app/consumers/deep/nesting/nestdir/deep_file.rb" ,
276- "# @team b\n class DeepFile end;" ,
277- ) ;
278-
279- let run_config = RunConfig {
280- project_root : temp_dir. path ( ) . to_path_buf ( ) ,
281- codeowners_file_path : temp_dir. path ( ) . join ( ".github/CODEOWNERS" ) . to_path_buf ( ) ,
282- config_path : temp_dir. path ( ) . join ( "config/code_ownership.yml" ) . to_path_buf ( ) ,
283- no_cache : false ,
284- } ;
285-
286- let file_owner = file_owner_for_file ( & run_config, "app/consumers/deep/nesting/nestdir/deep_file.rb" )
287- . unwrap ( )
288- . unwrap ( ) ;
289- assert_eq ! ( file_owner. team. name, "b" ) ;
290- assert_eq ! ( file_owner. team. github_team, "@b" ) ;
291- assert ! ( file_owner. team. path. to_string_lossy( ) . ends_with( "config/teams/b.yml" ) ) ;
292- assert_eq ! ( file_owner. sources. len( ) , 1 ) ;
293- assert_eq ! ( file_owner. sources, vec![ Source :: AnnotatedFile ] ) ;
294-
295- let team = team_for_file ( & run_config, "app/consumers/deep/nesting/nestdir/deep_file.rb" )
296- . unwrap ( )
297- . unwrap ( ) ;
298- assert_eq ! ( team. name, "b" ) ;
299- assert_eq ! ( team. github_team, "@b" ) ;
300- assert ! ( team. path. to_string_lossy( ) . ends_with( "config/teams/b.yml" ) ) ;
301- }
302-
303- #[ test]
304- fn test_teams_for_files_from_codeowners ( ) {
305- let project_root = Path :: new ( "tests/fixtures/valid_project" ) ;
306- let file_paths = [
307- "javascript/packages/items/item.ts" ,
308- "config/teams/payroll.yml" ,
309- "ruby/app/models/bank_account.rb" ,
310- "made/up/file.rb" ,
311- "ruby/ignored_files/git_ignored.rb" ,
312- ] ;
313- let run_config = RunConfig {
314- project_root : project_root. to_path_buf ( ) ,
315- codeowners_file_path : project_root. join ( ".github/CODEOWNERS" ) . to_path_buf ( ) ,
316- config_path : project_root. join ( "config/code_ownership.yml" ) . to_path_buf ( ) ,
317- no_cache : false ,
318- } ;
319- let teams =
320- teams_for_files_from_codeowners ( & run_config, & file_paths. iter ( ) . map ( |s| s. to_string ( ) ) . collect :: < Vec < String > > ( ) ) . unwrap ( ) ;
321- assert_eq ! ( teams. len( ) , 5 ) ;
322- assert_eq ! (
323- teams
324- . get( "javascript/packages/items/item.ts" )
325- . unwrap( )
326- . as_ref( )
327- . map( |t| t. name. as_str( ) ) ,
328- Some ( "Payroll" )
329- ) ;
330- assert_eq ! (
331- teams. get( "config/teams/payroll.yml" ) . unwrap( ) . as_ref( ) . map( |t| t. name. as_str( ) ) ,
332- Some ( "Payroll" )
333- ) ;
334- assert_eq ! (
335- teams
336- . get( "ruby/app/models/bank_account.rb" )
337- . unwrap( )
338- . as_ref( )
339- . map( |t| t. name. as_str( ) ) ,
340- Some ( "Payments" )
341- ) ;
342- assert_eq ! ( teams. get( "made/up/file.rb" ) . unwrap( ) . as_ref( ) . map( |t| t. name. as_str( ) ) , None ) ;
343- assert_eq ! (
344- teams
345- . get( "ruby/ignored_files/git_ignored.rb" )
346- . unwrap( )
347- . as_ref( )
348- . map( |t| t. name. as_str( ) ) ,
349- None
350- ) ;
351- assert_eq ! (
352- teams
353- . get( "ruby/ignored_files/git_ignored.rb" )
354- . unwrap( )
355- . as_ref( )
356- . map( |t| t. name. as_str( ) ) ,
357- None
358- ) ;
359- }
360251}
0 commit comments