Skip to content

Commit

Permalink
test: [#1251] add tests for whitelist is DB drivers WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Feb 10, 2025
1 parent 613efb2 commit 4d83116
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions packages/tracker-core/src/databases/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ mod tests {

// Whitelist (for listed trackers)

// todo
handling_the_whitelist::it_should_add_and_get_infohashes(driver);
handling_the_whitelist::it_should_remove_an_infohash_from_the_whitelist(driver);

driver.drop_database_tables().unwrap();
}
Expand All @@ -129,7 +130,7 @@ mod tests {
}
tokio::time::sleep(Duration::from_secs(2)).await;
}
Err("MySQL is not ready after retries.".into())
Err("Database is not ready after retries.".into())
}

mod handling_torrent_persistence {
Expand Down Expand Up @@ -208,4 +209,39 @@ mod tests {
assert!(driver.get_key_from_keys(&peer_key.key()).unwrap().is_none());
}
}

mod handling_the_whitelist {

use std::sync::Arc;

use crate::core_tests::sample_info_hash;
use crate::databases::Database;

pub fn it_should_add_and_get_infohashes(driver: &Arc<Box<dyn Database>>) {
let infohash = sample_info_hash();

driver.add_info_hash_to_whitelist(infohash).unwrap();

let stored_infohash = driver.get_info_hash_from_whitelist(infohash).unwrap().unwrap();

assert_eq!(stored_infohash, infohash);
}

pub fn it_should_remove_an_infohash_from_the_whitelist(driver: &Arc<Box<dyn Database>>) {
let infohash = sample_info_hash();

driver.add_info_hash_to_whitelist(infohash).unwrap();
driver.remove_info_hash_from_whitelist(infohash).unwrap();

assert!(driver.get_info_hash_from_whitelist(infohash).unwrap().is_none());
}

// todo:
//
// More tests:
// - it should not allow duplicate infohashes
//
// - Clear database before running tests.
// - Use random infohashes for the tests.
}
}

0 comments on commit 4d83116

Please sign in to comment.