forked from torrust/torrust-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge torrust#291: Add tags to torrent details in test responses
022692e fix: [torrust#273] add tags to torrent details in test responses (Jose Celano) Pull request description: In the **tests** the struct: ```rust pub struct TorrentDetails { pub torrent_id: Id, pub uploader: String, pub info_hash: String, pub title: String, pub description: String, pub category: Category, pub upload_date: UtcDateTime, pub file_size: u64, pub seeders: u64, pub leechers: u64, pub files: Vec<File>, pub trackers: Vec<String>, pub magnet_link: String, } ``` did not contain the torrent tags, so tests were not asserting that the tags were the expected ones. ACKs for top commit: josecelano: ACK 022692e Tree-SHA512: 01b155c68931321f9934931acec347c838462a9f1d6795bf2a092d9a607a940e112176ce819caefa0fe9ade48c22bec5dd0c8b8830c5a52e20f82823696e1a71
- Loading branch information
Showing
5 changed files
with
74 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
use super::responses::TorrentDetails; | ||
|
||
type Check = (&'static str, bool); | ||
|
||
/// Assert that the torrent details match the expected ones. | ||
/// | ||
/// It ignores some fields that are not relevant for the E2E tests | ||
/// or hard to assert due to the concurrent nature of the tests. | ||
pub fn assert_expected_torrent_details(torrent: &TorrentDetails, expected_torrent: &TorrentDetails) { | ||
assert_eq!( | ||
torrent.torrent_id, expected_torrent.torrent_id, | ||
"torrent `file_size` mismatch" | ||
); | ||
assert_eq!(torrent.uploader, expected_torrent.uploader, "torrent `uploader` mismatch"); | ||
assert_eq!(torrent.info_hash, expected_torrent.info_hash, "torrent `info_hash` mismatch"); | ||
assert_eq!(torrent.title, expected_torrent.title, "torrent `title` mismatch"); | ||
assert_eq!( | ||
torrent.description, expected_torrent.description, | ||
"torrent `description` mismatch" | ||
); | ||
assert_eq!( | ||
torrent.category.category_id, expected_torrent.category.category_id, | ||
"torrent `category.category_id` mismatch" | ||
); | ||
assert_eq!( | ||
torrent.category.name, expected_torrent.category.name, | ||
"torrent `category.name` mismatch" | ||
); | ||
// assert_eq!(torrent.category.num_torrents, expected_torrent.category.num_torrents, "torrent `category.num_torrents` mismatch"); // Ignored | ||
// assert_eq!(torrent.upload_date, expected_torrent.upload_date, "torrent `upload_date` mismatch"); // Ignored, can't mock time easily for now. | ||
assert_eq!(torrent.file_size, expected_torrent.file_size, "torrent `file_size` mismatch"); | ||
assert_eq!(torrent.seeders, expected_torrent.seeders, "torrent `seeders` mismatch"); | ||
assert_eq!(torrent.leechers, expected_torrent.leechers, "torrent `leechers` mismatch"); | ||
assert_eq!(torrent.files, expected_torrent.files, "torrent `files` mismatch"); | ||
assert_eq!(torrent.trackers, expected_torrent.trackers, "torrent `trackers` mismatch"); | ||
assert_eq!( | ||
torrent.magnet_link, expected_torrent.magnet_link, | ||
"torrent `magnet_link` mismatch" | ||
); | ||
let mut discrepancies = Vec::new(); | ||
|
||
let checks: Vec<Check> = vec![ | ||
("torrent_id", torrent.torrent_id == expected_torrent.torrent_id), | ||
("uploader", torrent.uploader == expected_torrent.uploader), | ||
("info_hash", torrent.info_hash == expected_torrent.info_hash), | ||
("title", torrent.title == expected_torrent.title), | ||
("description", torrent.description == expected_torrent.description), | ||
( | ||
"category.category_id", | ||
torrent.category.category_id == expected_torrent.category.category_id, | ||
), | ||
("category.name", torrent.category.name == expected_torrent.category.name), | ||
("file_size", torrent.file_size == expected_torrent.file_size), | ||
("seeders", torrent.seeders == expected_torrent.seeders), | ||
("leechers", torrent.leechers == expected_torrent.leechers), | ||
("files", torrent.files == expected_torrent.files), | ||
("trackers", torrent.trackers == expected_torrent.trackers), | ||
("magnet_link", torrent.magnet_link == expected_torrent.magnet_link), | ||
("tags", torrent.tags == expected_torrent.tags), | ||
("name", torrent.name == expected_torrent.name), | ||
]; | ||
|
||
for (field_name, equals) in &checks { | ||
if !equals { | ||
discrepancies.push((*field_name).to_string()); | ||
} | ||
} | ||
|
||
let error_message = format!("left:\n{torrent:#?}\nright:\n{expected_torrent:#?}\ndiscrepancies: {discrepancies:#?}"); | ||
|
||
assert!(discrepancies.is_empty(), "{}", error_message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters