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;
@@ -10,20 +11,18 @@ use cargo_registry::{
1011} ;
1112use std:: { rc:: Rc , sync:: Arc , time:: Duration } ;
1213
13- use cargo_registry:: git:: { Repository as WorkerRepository , Repository } ;
14+ use cargo_registry:: git:: Repository as WorkerRepository ;
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,30 +128,15 @@ 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_index ( & self ) -> & UpstreamIndex {
132+ assert_some ! ( self . 0 . index. as_ref( ) )
134133 }
135134
136135 /// Obtain a list of crates from the index HEAD
137136 pub fn crates_from_index_head ( & self , crate_name : & str ) -> Vec < cargo_registry:: git:: Crate > {
138- let path = Repository :: relative_index_file ( crate_name) ;
139- let index = self . upstream_repository ( ) ;
140- let tree = index. head ( ) . unwrap ( ) . peel_to_tree ( ) . unwrap ( ) ;
141- let blob = tree
142- . get_path ( & path)
137+ self . upstream_index ( )
138+ . crates_from_index_head ( crate_name)
143139 . unwrap ( )
144- . to_object ( index)
145- . unwrap ( )
146- . peel_to_blob ( )
147- . unwrap ( ) ;
148- let content = blob. content ( ) ;
149-
150- // The index format consists of one JSON object per line
151- // It is not a JSON array
152- let lines = std:: str:: from_utf8 ( content) . unwrap ( ) . lines ( ) ;
153- lines
154- . map ( |line| serde_json:: from_str ( line) . unwrap ( ) )
155- . collect ( )
156140 }
157141
158142 pub fn run_pending_background_jobs ( & self ) {
@@ -186,15 +170,13 @@ pub struct TestAppBuilder {
186170 config : config:: Server ,
187171 proxy : Option < String > ,
188172 bomb : Option < record:: Bomb > ,
189- index : Option < UpstreamRepository > ,
173+ index : Option < UpstreamIndex > ,
190174 build_job_runner : bool ,
191175}
192176
193177impl TestAppBuilder {
194178 /// Create a `TestApp` with an empty database
195179 pub fn empty ( mut self ) -> ( TestApp , MockAnonymousUser ) {
196- use crate :: git;
197-
198180 // Run each test inside a fresh database schema, deleted at the end of the test,
199181 // The schema will be cleared up once the app is dropped.
200182 let ( db_chaosproxy, fresh_schema) = if !self . config . use_test_database_pool {
@@ -211,7 +193,7 @@ impl TestAppBuilder {
211193
212194 let runner = if self . build_job_runner {
213195 let repository_config = RepositoryConfig {
214- index_location : Url :: from_file_path ( & git :: bare ( ) ) . unwrap ( ) ,
196+ index_location : UpstreamIndex :: url ( ) ,
215197 credentials : Credentials :: Missing ,
216198 } ;
217199 let index = WorkerRepository :: open ( & repository_config) . expect ( "Could not clone index" ) ;
@@ -286,12 +268,7 @@ impl TestAppBuilder {
286268 }
287269
288270 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 ( ) ) ;
271+ self . index = Some ( UpstreamIndex :: new ( ) . unwrap ( ) ) ;
295272 self
296273 }
297274
0 commit comments