@@ -292,31 +292,31 @@ mod test {
292292 default:: Default ,
293293 env,
294294 io:: Read ,
295- path:: PathBuf ,
295+ path:: { Path , PathBuf } ,
296296 sync:: { Arc , Mutex } ,
297297 } ;
298298
299- use chrono:: Utc ;
300- use mockito:: { Matcher , Server } ;
301299 use regex:: Regex ;
302- use reqwest:: { Method , Url } ;
303300 use tempfile:: { tempdir, NamedTempFile } ;
304301
305302 use super :: GithubApiClient ;
306303 use crate :: {
307304 clang_tools:: capture_clang_tools_output,
308305 cli:: { ClangParams , FeedbackInput , LinesChangedOnly } ,
309- common_fs:: FileObj ,
306+ common_fs:: { FileFilter , FileObj } ,
307+ logger,
310308 rest_api:: { RestApiClient , USER_OUTREACH } ,
311309 } ;
312310
313311 // ************************* tests for step-summary and output variables
314312
315- async fn create_comment ( tidy_checks : & str , style : & str ) -> ( String , String ) {
313+ async fn create_comment ( tidy_checks : & str , style : & str , fail_gh_out : bool ) -> ( String , String ) {
316314 let tmp_dir = tempdir ( ) . unwrap ( ) ;
317315 let rest_api_client = GithubApiClient :: new ( ) . unwrap ( ) ;
316+ logger:: init ( ) . unwrap ( ) ;
318317 if env:: var ( "ACTIONS_STEP_DEBUG" ) . is_ok_and ( |var| var == "true" ) {
319318 assert ! ( rest_api_client. debug_enabled) ;
319+ log:: set_max_level ( log:: LevelFilter :: Debug ) ;
320320 }
321321 let mut files = vec ! [ Arc :: new( Mutex :: new( FileObj :: new( PathBuf :: from(
322322 "tests/demo/demo.cpp" ,
@@ -342,7 +342,14 @@ mod test {
342342 let mut step_summary_path = NamedTempFile :: new_in ( tmp_dir. path ( ) ) . unwrap ( ) ;
343343 env:: set_var ( "GITHUB_STEP_SUMMARY" , step_summary_path. path ( ) ) ;
344344 let mut gh_out_path = NamedTempFile :: new_in ( tmp_dir. path ( ) ) . unwrap ( ) ;
345- env:: set_var ( "GITHUB_OUTPUT" , gh_out_path. path ( ) ) ;
345+ env:: set_var (
346+ "GITHUB_OUTPUT" ,
347+ if fail_gh_out {
348+ Path :: new ( "not-a-file.txt" )
349+ } else {
350+ gh_out_path. path ( )
351+ } ,
352+ ) ;
346353 rest_api_client
347354 . post_feedback ( & files, feedback_inputs)
348355 . await
@@ -354,13 +361,15 @@ mod test {
354361 assert ! ( & step_summary_content. contains( USER_OUTREACH ) ) ;
355362 let mut gh_out_content = String :: new ( ) ;
356363 gh_out_path. read_to_string ( & mut gh_out_content) . unwrap ( ) ;
357- assert ! ( gh_out_content. starts_with( "checks-failed=" ) ) ;
364+ if !fail_gh_out {
365+ assert ! ( gh_out_content. starts_with( "checks-failed=" ) ) ;
366+ }
358367 ( step_summary_content, gh_out_content)
359368 }
360369
361370 #[ tokio:: test]
362371 async fn check_comment_concerns ( ) {
363- let ( comment, gh_out) = create_comment ( "readability-*" , "file" ) . await ;
372+ let ( comment, gh_out) = create_comment ( "readability-*" , "file" , false ) . await ;
364373 assert ! ( & comment. contains( ":warning:\n Some files did not pass the configured checks!\n " ) ) ;
365374 let fmt_pattern = Regex :: new ( r"format-checks-failed=(\d+)\n" ) . unwrap ( ) ;
366375 let tidy_pattern = Regex :: new ( r"tidy-checks-failed=(\d+)\n" ) . unwrap ( ) ;
@@ -380,61 +389,31 @@ mod test {
380389 #[ tokio:: test]
381390 async fn check_comment_lgtm ( ) {
382391 env:: set_var ( "ACTIONS_STEP_DEBUG" , "true" ) ;
383- let ( comment, gh_out) = create_comment ( "-*" , "" ) . await ;
392+ let ( comment, gh_out) = create_comment ( "-*" , "" , false ) . await ;
384393 assert ! ( & comment. contains( ":heavy_check_mark:\n No problems need attention." ) ) ;
385394 assert_eq ! (
386395 & gh_out,
387396 "checks-failed=0\n format-checks-failed=0\n tidy-checks-failed=0\n "
388397 ) ;
389398 }
390399
391- async fn simulate_rate_limit ( secondary : bool ) {
392- let mut server = Server :: new_async ( ) . await ;
393- let url = Url :: parse ( server. url ( ) . as_str ( ) ) . unwrap ( ) ;
394- env:: set_var ( "GITHUB_API_URL" , server. url ( ) ) ;
395- let client = GithubApiClient :: new ( ) . unwrap ( ) ;
396- let reset_timestamp = ( Utc :: now ( ) . timestamp ( ) + 60 ) . to_string ( ) ;
397- let mock = server
398- . mock ( "GET" , "/" )
399- . match_body ( Matcher :: Any )
400- . expect_at_least ( 1 )
401- . expect_at_most ( 5 )
402- . with_status ( 429 )
403- . with_header (
404- & client. rate_limit_headers . remaining ,
405- if secondary { "1" } else { "0" } ,
406- )
407- . with_header ( & client. rate_limit_headers . reset , & reset_timestamp) ;
408- if secondary {
409- mock. with_header ( & client. rate_limit_headers . retry , "0" )
410- . create ( ) ;
411- } else {
412- mock. create ( ) ;
413- }
414- let request =
415- GithubApiClient :: make_api_request ( & client. client , url, Method :: GET , None , None )
416- . unwrap ( ) ;
417- GithubApiClient :: send_api_request (
418- client. client . clone ( ) ,
419- request,
420- client. rate_limit_headers . clone ( ) ,
421- 0 ,
422- )
423- . await
424- . unwrap ( ) ;
425- }
426-
427400 #[ tokio:: test]
428- #[ ignore]
429- #[ should_panic( expected = "REST API secondary rate limit exceeded" ) ]
430- async fn secondary_rate_limit ( ) {
431- simulate_rate_limit ( true ) . await ;
401+ async fn fail_gh_output ( ) {
402+ env:: set_var ( "ACTIONS_STEP_DEBUG" , "true" ) ;
403+ let ( comment, gh_out) = create_comment ( "-*" , "" , true ) . await ;
404+ assert ! ( & comment. contains( ":heavy_check_mark:\n No problems need attention." ) ) ;
405+ assert_eq ! ( & gh_out, "" ) ;
432406 }
433407
434408 #[ tokio:: test]
435- #[ ignore]
436- #[ should_panic( expected = "REST API rate limit exceeded!" ) ]
437- async fn primary_rate_limit ( ) {
438- simulate_rate_limit ( false ) . await ;
409+ async fn fail_get_local_diff ( ) {
410+ env:: set_var ( "CI" , "false" ) ;
411+ let tmp_dir = tempdir ( ) . unwrap ( ) ;
412+ env:: set_current_dir ( tmp_dir. path ( ) ) . unwrap ( ) ;
413+ let rest_client = GithubApiClient :: new ( ) . unwrap ( ) ;
414+ let files = rest_client
415+ . get_list_of_changed_files ( & FileFilter :: new ( & [ ] , vec ! [ ] ) )
416+ . await ;
417+ assert ! ( files. is_err( ) )
439418 }
440419}
0 commit comments