@@ -5,13 +5,9 @@ use crate::cdn::CdnBackend;
55use crate :: config:: ConfigBuilder ;
66use crate :: db:: { self , AsyncPoolClient , Pool } ;
77use crate :: error:: Result ;
8- use crate :: repositories:: RepositoryStatsUpdater ;
98use crate :: storage:: { AsyncStorage , Storage , StorageKind } ;
109use crate :: web:: { build_axum_app, cache, page:: TemplateData } ;
11- use crate :: {
12- AsyncBuildQueue , BuildQueue , Config , Context , Index , InstanceMetrics , RegistryApi ,
13- ServiceMetrics ,
14- } ;
10+ use crate :: { AsyncBuildQueue , BuildQueue , Config , Context , InstanceMetrics } ;
1511use anyhow:: Context as _;
1612use axum:: body:: Bytes ;
1713use axum:: { Router , body:: Body , http:: Request , response:: Response as AxumResponse } ;
@@ -358,73 +354,13 @@ impl TestEnvironment {
358354 // create index directory
359355 fs:: create_dir_all ( config. registry_index_path . clone ( ) ) ?;
360356
361- let config = Arc :: new ( config) ;
362- let instance_metrics =
363- Arc :: new ( InstanceMetrics :: new ( ) . context ( "failed to initialize the instance metrics" ) ?) ;
364-
357+ let instance_metrics = Arc :: new ( InstanceMetrics :: new ( ) ?) ;
365358 let test_db = TestDatabase :: new ( & config, instance_metrics. clone ( ) )
366359 . await
367360 . context ( "can't initialize test database" ) ?;
368- let pool = test_db. pool ( ) ;
369-
370- let async_storage = Arc :: new (
371- AsyncStorage :: new ( pool. clone ( ) , instance_metrics. clone ( ) , config. clone ( ) )
372- . await
373- . context ( "can't create async storage" ) ?,
374- ) ;
375-
376- let async_build_queue = Arc :: new ( AsyncBuildQueue :: new (
377- pool. clone ( ) ,
378- instance_metrics. clone ( ) ,
379- config. clone ( ) ,
380- async_storage. clone ( ) ,
381- ) ) ;
382-
383- let runtime = runtime:: Handle :: current ( ) ;
384-
385- let build_queue = Arc :: new ( BuildQueue :: new ( runtime. clone ( ) , async_build_queue. clone ( ) ) ) ;
386-
387- let storage = Arc :: new ( Storage :: new ( async_storage. clone ( ) , runtime. clone ( ) ) ) ;
388-
389- let cdn = Arc :: new ( CdnBackend :: new ( & config) . await ) ;
390-
391- let index = Arc :: new ( {
392- let path = config. registry_index_path . clone ( ) ;
393- if let Some ( registry_url) = config. registry_url . clone ( ) {
394- Index :: from_url ( path, registry_url)
395- } else {
396- Index :: new ( path)
397- }
398- . context ( "can't create Index" ) ?
399- } ) ;
400361
401362 Ok ( Self {
402- context : Context {
403- config : config. clone ( ) ,
404- async_build_queue,
405- build_queue,
406- storage,
407- async_storage,
408- cdn,
409- pool : pool. clone ( ) ,
410- service_metrics : Arc :: new (
411- ServiceMetrics :: new ( ) . context ( "can't initialize service metrics" ) ?,
412- ) ,
413- instance_metrics,
414- index,
415- registry_api : Arc :: new (
416- RegistryApi :: new (
417- config. registry_api_host . clone ( ) ,
418- config. crates_io_api_call_retries ,
419- )
420- . context ( "can't create registry api" ) ?,
421- ) ,
422- repository_stats_updater : Arc :: new ( RepositoryStatsUpdater :: new (
423- & config,
424- pool. clone ( ) ,
425- ) ) ,
426- runtime,
427- } ,
363+ context : Context :: from_config ( config, instance_metrics, test_db. pool ( ) . clone ( ) ) . await ?,
428364 db : test_db,
429365 owned_runtime : None ,
430366 } )
0 commit comments