1- use assert_cmd:: prelude:: * ;
21use indoc:: indoc;
32use predicates:: prelude:: * ;
4- use std:: { error:: Error , process:: Command } ;
3+ use std:: error:: Error ;
4+
5+ mod common;
6+ use common:: OutputStream ;
7+ use common:: run_codeowners;
58
69#[ test]
710fn test_validate ( ) -> Result < ( ) , Box < dyn Error > > {
8- Command :: cargo_bin ( "codeowners" ) ?
9- . arg ( "--project-root" )
10- . arg ( "tests/fixtures/invalid_project" )
11- . arg ( "--no-cache" )
12- . arg ( "validate" )
13- . assert ( )
14- . failure ( )
15- . stdout ( predicate:: eq ( indoc ! { "
11+ run_codeowners (
12+ "invalid_project" ,
13+ & [ "validate" ] ,
14+ false ,
15+ OutputStream :: Stdout ,
16+ predicate:: eq ( indoc ! { "
1617
17- CODEOWNERS out of date. Run `codeowners generate` to update the CODEOWNERS file
18+ CODEOWNERS out of date. Run `codeowners generate` to update the CODEOWNERS file
1819
19- Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways
20+ Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways
2021
21- gems/payroll_calculator/calculator.rb
22- owner: Payments
23- - Owner annotation at the top of the file
24- owner: Payroll
25- - Owner specified in Team YML's `owned_gems`
22+ gems/payroll_calculator/calculator.rb
23+ owner: Payments
24+ - Owner annotation at the top of the file
25+ owner: Payroll
26+ - Owner specified in Team YML's `owned_gems`
2627
27- ruby/app/services/multi_owned.rb
28- owner: Payments
29- - Owner annotation at the top of the file
30- owner: Payroll
31- - Owner specified in `ruby/app/services/.codeowner`
28+ ruby/app/services/multi_owned.rb
29+ owner: Payments
30+ - Owner annotation at the top of the file
31+ owner: Payroll
32+ - Owner specified in `ruby/app/services/.codeowner`
3233
33- Found invalid team annotations
34- - ruby/app/models/blockchain.rb is referencing an invalid team - 'Web3'
34+ Found invalid team annotations
35+ - ruby/app/models/blockchain.rb is referencing an invalid team - 'Web3'
3536
36- Some files are missing ownership
37- - ruby/app/unowned.rb
37+ Some files are missing ownership
38+ - ruby/app/unowned.rb
3839
39- " } ) ) ;
40+ " } ) ,
41+ ) ?;
4042 Ok ( ( ) )
4143}
4244
4345#[ test]
4446fn test_for_file ( ) -> Result < ( ) , Box < dyn Error > > {
45- Command :: cargo_bin ( "codeowners" ) ?
46- . arg ( "--project-root" )
47- . arg ( "tests/fixtures/invalid_project" )
48- . arg ( "--no-cache" )
49- . arg ( "for-file" )
50- . arg ( "ruby/app/models/blockchain.rb" )
51- . assert ( )
52- . success ( )
53- . stdout ( predicate:: eq ( indoc ! { "
47+ run_codeowners (
48+ "invalid_project" ,
49+ & [ "for-file" , "ruby/app/models/blockchain.rb" ] ,
50+ true ,
51+ OutputStream :: Stdout ,
52+ predicate:: eq ( indoc ! { "
5453 Team: Unowned
5554 Github Team: Unowned
5655 Team YML:
5756 Description:
5857 - Unowned
59- " } ) ) ;
58+ " } ) ,
59+ ) ?;
6060 Ok ( ( ) )
6161}
6262
6363#[ test]
6464fn test_for_file_multiple_owners ( ) -> Result < ( ) , Box < dyn Error > > {
65- Command :: cargo_bin ( "codeowners" ) ?
66- . arg ( "--project-root" )
67- . arg ( "tests/fixtures/invalid_project" )
68- . arg ( "--no-cache" )
69- . arg ( "for-file" )
70- . arg ( "ruby/app/services/multi_owned.rb" )
71- . assert ( )
72- . failure ( )
73- . stdout ( predicate:: eq ( indoc ! { "
65+ run_codeowners (
66+ "invalid_project" ,
67+ & [ "for-file" , "ruby/app/services/multi_owned.rb" ] ,
68+ false ,
69+ OutputStream :: Stdout ,
70+ predicate:: eq ( indoc ! { "
7471 Error: file is owned by multiple teams!
7572
7673 Team: Payments
@@ -84,6 +81,7 @@ fn test_for_file_multiple_owners() -> Result<(), Box<dyn Error>> {
8481 Team YML: config/teams/payroll.yml
8582 Description:
8683 - Owner specified in `ruby/app/services/.codeowner`
87- " } ) ) ;
84+ " } ) ,
85+ ) ?;
8886 Ok ( ( ) )
8987}
0 commit comments