11use super :: { MockAnonymousUser , MockCookieUser , MockTokenUser } ;
2+ use crate :: git:: UpstreamIndex ;
23use crate :: record;
34use crate :: util:: { chaosproxy:: ChaosProxy , fresh_schema:: FreshSchema } ;
45use cargo_registry:: config;
@@ -12,18 +13,16 @@ use std::{rc::Rc, sync::Arc, time::Duration};
1213
1314use cargo_registry:: git:: { Repository as WorkerRepository , Repository } ;
1415use diesel:: PgConnection ;
15- use git2:: Repository as UpstreamRepository ;
1616use reqwest:: { blocking:: Client , Proxy } ;
1717use std:: collections:: HashSet ;
1818use swirl:: Runner ;
19- use url:: Url ;
2019
2120struct TestAppInner {
2221 app : Arc < App > ,
2322 // The bomb (if created) needs to be held in scope until the end of the test.
2423 _bomb : Option < record:: Bomb > ,
2524 middle : conduit_middleware:: MiddlewareBuilder ,
26- index : Option < UpstreamRepository > ,
25+ index : Option < UpstreamIndex > ,
2726 runner : Option < Runner < Environment , DieselPool > > ,
2827 db_chaosproxy : Option < Arc < ChaosProxy > > ,
2928
@@ -129,8 +128,9 @@ impl TestApp {
129128 }
130129
131130 /// Obtain a reference to the upstream repository ("the index")
132- pub fn upstream_repository ( & self ) -> & UpstreamRepository {
133- self . 0 . index . as_ref ( ) . unwrap ( )
131+ pub fn upstream_repository ( & self ) -> & git2:: Repository {
132+ let index = self . 0 . index . as_ref ( ) . unwrap ( ) ;
133+ & index. repository
134134 }
135135
136136 /// Obtain a list of crates from the index HEAD
@@ -186,15 +186,13 @@ pub struct TestAppBuilder {
186186 config : config:: Server ,
187187 proxy : Option < String > ,
188188 bomb : Option < record:: Bomb > ,
189- index : Option < UpstreamRepository > ,
189+ index : Option < UpstreamIndex > ,
190190 build_job_runner : bool ,
191191}
192192
193193impl TestAppBuilder {
194194 /// Create a `TestApp` with an empty database
195195 pub fn empty ( mut self ) -> ( TestApp , MockAnonymousUser ) {
196- use crate :: git;
197-
198196 // Run each test inside a fresh database schema, deleted at the end of the test,
199197 // The schema will be cleared up once the app is dropped.
200198 let ( db_chaosproxy, fresh_schema) = if !self . config . use_test_database_pool {
@@ -211,7 +209,7 @@ impl TestAppBuilder {
211209
212210 let runner = if self . build_job_runner {
213211 let repository_config = RepositoryConfig {
214- index_location : Url :: from_file_path ( & git :: bare ( ) ) . unwrap ( ) ,
212+ index_location : UpstreamIndex :: url ( ) ,
215213 credentials : Credentials :: Missing ,
216214 } ;
217215 let index = WorkerRepository :: open ( & repository_config) . expect ( "Could not clone index" ) ;
@@ -286,12 +284,7 @@ impl TestAppBuilder {
286284 }
287285
288286 pub fn with_git_index ( mut self ) -> Self {
289- use crate :: git;
290-
291- git:: init ( ) ;
292-
293- let thread_local_path = git:: bare ( ) ;
294- self . index = Some ( UpstreamRepository :: open_bare ( thread_local_path) . unwrap ( ) ) ;
287+ self . index = Some ( UpstreamIndex :: new ( ) . unwrap ( ) ) ;
295288 self
296289 }
297290
0 commit comments