diff --git a/src/core/mod.rs b/src/core/mod.rs index a9fe2a8a6..4136966d2 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -481,13 +481,14 @@ use crate::CurrentClock; /// > Typically, the `Tracker` is used by a higher application service that handles /// > the network layer. pub struct Tracker { + // The tracker configuration. config: Core, /// A database driver implementation: [`Sqlite3`](crate::core::databases::sqlite) /// or [`MySQL`](crate::core::databases::mysql) - pub database: Arc>, + database: Arc>, keys: tokio::sync::RwLock>, whitelist: tokio::sync::RwLock>, - pub torrents: Arc, + torrents: Arc, stats_event_sender: Option>, stats_repository: statistics::Repo, } @@ -987,6 +988,17 @@ impl Tracker { Some(stats_event_sender) => stats_event_sender.send_event(event).await, } } + + /// It drops the database tables. + /// + /// # Errors + /// + /// Will return `Err` if unable to drop tables. + pub fn drop_database_tables(&self) -> Result<(), databases::error::Error> { + // todo: this is only used for testing. WE have to pass the database + // reference directly to the tests instead of via the tracker. + self.database.drop_database_tables() + } } #[must_use] diff --git a/tests/servers/api/mod.rs b/tests/servers/api/mod.rs index 9c30e316a..38df46e9b 100644 --- a/tests/servers/api/mod.rs +++ b/tests/servers/api/mod.rs @@ -11,7 +11,10 @@ pub type Started = environment::Environment; /// It forces a database error by dropping all tables. /// That makes any query fail. -/// code-review: alternatively we could inject a database mock in the future. +/// code-review: +/// Alternatively we could: +/// - Inject a database mock in the future. +/// - Inject directly the database reference passed to the Tracker type. pub fn force_database_error(tracker: &Arc) { - tracker.database.drop_database_tables().unwrap(); + tracker.drop_database_tables().unwrap(); }