Parent issue: #1181
The following code code is repeated many times in tests. It's the initialization of the application services.
let cfg = Arc::new(ephemeral_public());
let config = &cfg.http_api.clone().unwrap();
let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));
let (stats_event_sender, stats_repository) = statistics::setup::factory(cfg.core.tracker_usage_statistics);
let stats_event_sender = Arc::new(stats_event_sender);
let stats_repository = Arc::new(stats_repository);
initialize_global_services(&cfg);
let database = initialize_database(&cfg);
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
&cfg.core,
&in_memory_whitelist.clone(),
));
let whitelist_manager = initialize_whitelist_manager(database.clone(), in_memory_whitelist.clone());
let db_key_repository = Arc::new(DatabaseKeyRepository::new(&database));
let in_memory_key_repository = Arc::new(InMemoryKeyRepository::default());
let _authentication_service = Arc::new(service::AuthenticationService::new(&cfg.core, &in_memory_key_repository));
let keys_handler = Arc::new(KeysHandler::new(
&db_key_repository.clone(),
&in_memory_key_repository.clone(),
));
let authentication = Arc::new(authentication::Facade::new(&keys_handler));
let tracker = Arc::new(initialize_tracker(&cfg, &database, &whitelist_authorization, &authentication));
We now have the AppContainer and it's initialized here.
The initialization is not exactly the same in all tests because in some tests some services are not needed or mocked. However I think we can extract a simple abstraction or even a builder in the future. For now, I'm just going to remove the duplication as much as possible.
Parent issue: #1181
The following code code is repeated many times in tests. It's the initialization of the application services.
We now have the
AppContainerand it's initialized here.The initialization is not exactly the same in all tests because in some tests some services are not needed or mocked. However I think we can extract a simple abstraction or even a builder in the future. For now, I'm just going to remove the duplication as much as possible.