1
1
use super :: { MockAnonymousUser , MockCookieUser , MockTokenUser } ;
2
+ use crate :: git:: UpstreamIndex ;
2
3
use crate :: record;
3
4
use crate :: util:: { chaosproxy:: ChaosProxy , fresh_schema:: FreshSchema } ;
4
5
use cargo_registry:: config;
@@ -10,20 +11,18 @@ use cargo_registry::{
10
11
} ;
11
12
use std:: { rc:: Rc , sync:: Arc , time:: Duration } ;
12
13
13
- use cargo_registry:: git:: { Repository as WorkerRepository , Repository } ;
14
+ use cargo_registry:: git:: Repository as WorkerRepository ;
14
15
use diesel:: PgConnection ;
15
- use git2:: Repository as UpstreamRepository ;
16
16
use reqwest:: { blocking:: Client , Proxy } ;
17
17
use std:: collections:: HashSet ;
18
18
use swirl:: Runner ;
19
- use url:: Url ;
20
19
21
20
struct TestAppInner {
22
21
app : Arc < App > ,
23
22
// The bomb (if created) needs to be held in scope until the end of the test.
24
23
_bomb : Option < record:: Bomb > ,
25
24
middle : conduit_middleware:: MiddlewareBuilder ,
26
- index : Option < UpstreamRepository > ,
25
+ index : Option < UpstreamIndex > ,
27
26
runner : Option < Runner < Environment , DieselPool > > ,
28
27
db_chaosproxy : Option < Arc < ChaosProxy > > ,
29
28
@@ -129,30 +128,15 @@ impl TestApp {
129
128
}
130
129
131
130
/// 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( ) )
134
133
}
135
134
136
135
/// Obtain a list of crates from the index HEAD
137
136
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)
143
139
. 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 ( )
156
140
}
157
141
158
142
pub fn run_pending_background_jobs ( & self ) {
@@ -186,15 +170,13 @@ pub struct TestAppBuilder {
186
170
config : config:: Server ,
187
171
proxy : Option < String > ,
188
172
bomb : Option < record:: Bomb > ,
189
- index : Option < UpstreamRepository > ,
173
+ index : Option < UpstreamIndex > ,
190
174
build_job_runner : bool ,
191
175
}
192
176
193
177
impl TestAppBuilder {
194
178
/// Create a `TestApp` with an empty database
195
179
pub fn empty ( mut self ) -> ( TestApp , MockAnonymousUser ) {
196
- use crate :: git;
197
-
198
180
// Run each test inside a fresh database schema, deleted at the end of the test,
199
181
// The schema will be cleared up once the app is dropped.
200
182
let ( db_chaosproxy, fresh_schema) = if !self . config . use_test_database_pool {
@@ -211,7 +193,7 @@ impl TestAppBuilder {
211
193
212
194
let runner = if self . build_job_runner {
213
195
let repository_config = RepositoryConfig {
214
- index_location : Url :: from_file_path ( & git :: bare ( ) ) . unwrap ( ) ,
196
+ index_location : UpstreamIndex :: url ( ) ,
215
197
credentials : Credentials :: Missing ,
216
198
} ;
217
199
let index = WorkerRepository :: open ( & repository_config) . expect ( "Could not clone index" ) ;
@@ -286,12 +268,7 @@ impl TestAppBuilder {
286
268
}
287
269
288
270
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 ( ) ) ;
295
272
self
296
273
}
297
274
0 commit comments