@@ -12,6 +12,7 @@ use crate::tests::util::chaosproxy::ChaosProxy;
1212use crate :: tests:: util:: github:: MOCK_GITHUB_DATA ;
1313use crate :: worker:: { Environment , RunnerExt } ;
1414use crate :: { App , Emails , Env } ;
15+ use crates_io_github:: MockGitHubClient ;
1516use crates_io_index:: testing:: UpstreamIndex ;
1617use crates_io_index:: { Credentials , RepositoryConfig } ;
1718use crates_io_team_repo:: MockTeamRepo ;
@@ -103,6 +104,7 @@ impl TestApp {
103104 build_job_runner : false ,
104105 use_chaos_proxy : false ,
105106 team_repo : MockTeamRepo :: new ( ) ,
107+ github : None ,
106108 }
107109 }
108110
@@ -252,6 +254,7 @@ pub struct TestAppBuilder {
252254 build_job_runner : bool ,
253255 use_chaos_proxy : bool ,
254256 team_repo : MockTeamRepo ,
257+ github : Option < MockGitHubClient > ,
255258}
256259
257260impl TestAppBuilder {
@@ -296,7 +299,7 @@ impl TestAppBuilder {
296299 ( primary_proxy, replica_proxy)
297300 } ;
298301
299- let ( app, router) = build_app ( self . config ) ;
302+ let ( app, router) = build_app ( self . config , self . github ) ;
300303
301304 let runner = if self . build_job_runner {
302305 let index = self
@@ -397,6 +400,11 @@ impl TestAppBuilder {
397400 self
398401 }
399402
403+ pub fn with_github ( mut self , github : MockGitHubClient ) -> Self {
404+ self . github = Some ( github) ;
405+ self
406+ }
407+
400408 pub fn with_team_repo ( mut self , team_repo : MockTeamRepo ) -> Self {
401409 self . team_repo = team_repo;
402410 self
@@ -487,14 +495,13 @@ fn simple_config() -> config::Server {
487495 }
488496}
489497
490- fn build_app ( config : config:: Server ) -> ( Arc < App > , axum:: Router ) {
498+ fn build_app ( config : config:: Server , github : Option < MockGitHubClient > ) -> ( Arc < App > , axum:: Router ) {
491499 // Use the in-memory email backend for all tests, allowing tests to analyze the emails sent by
492500 // the application. This will also prevent cluttering the filesystem.
493501 let emails = Emails :: new_in_memory ( ) ;
494502
495- // Use a custom mock for the GitHub client, allowing to define the GitHub users and
496- // organizations without actually having to create GitHub accounts.
497- let github = Box :: new ( MOCK_GITHUB_DATA . as_mock_client ( ) ) ;
503+ let github = github. unwrap_or_else ( || MOCK_GITHUB_DATA . as_mock_client ( ) ) ;
504+ let github = Box :: new ( github) ;
498505
499506 let app = App :: new ( config, emails, github) ;
500507
0 commit comments