Skip to content

Commit 5a16ea1

Browse files
committed
refactor: [#932] make all Tracker fields private
1 parent a5b9e14 commit 5a16ea1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/core/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,14 @@ use crate::CurrentClock;
481481
/// > Typically, the `Tracker` is used by a higher application service that handles
482482
/// > the network layer.
483483
pub struct Tracker {
484+
// The tracker configuration.
484485
config: Core,
485486
/// A database driver implementation: [`Sqlite3`](crate::core::databases::sqlite)
486487
/// or [`MySQL`](crate::core::databases::mysql)
487-
pub database: Arc<Box<dyn Database>>,
488+
database: Arc<Box<dyn Database>>,
488489
keys: tokio::sync::RwLock<std::collections::HashMap<Key, auth::ExpiringKey>>,
489490
whitelist: tokio::sync::RwLock<std::collections::HashSet<InfoHash>>,
490-
pub torrents: Arc<Torrents>,
491+
torrents: Arc<Torrents>,
491492
stats_event_sender: Option<Box<dyn statistics::EventSender>>,
492493
stats_repository: statistics::Repo,
493494
}
@@ -987,6 +988,17 @@ impl Tracker {
987988
Some(stats_event_sender) => stats_event_sender.send_event(event).await,
988989
}
989990
}
991+
992+
/// It drops the database tables.
993+
///
994+
/// # Errors
995+
///
996+
/// Will return `Err` if unable to drop tables.
997+
pub fn drop_database_tables(&self) -> Result<(), databases::error::Error> {
998+
// todo: this is only used for testing. WE have to pass the database
999+
// reference directly to the tests instead of via the tracker.
1000+
self.database.drop_database_tables()
1001+
}
9901002
}
9911003

9921004
#[must_use]

tests/servers/api/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ pub type Started = environment::Environment<server::Running>;
1111

1212
/// It forces a database error by dropping all tables.
1313
/// That makes any query fail.
14-
/// code-review: alternatively we could inject a database mock in the future.
14+
/// code-review:
15+
/// Alternatively we could:
16+
/// - Inject a database mock in the future.
17+
/// - Inject directly the database reference passed to the Tracker type.
1518
pub fn force_database_error(tracker: &Arc<Tracker>) {
16-
tracker.database.drop_database_tables().unwrap();
19+
tracker.drop_database_tables().unwrap();
1720
}

0 commit comments

Comments
 (0)