Skip to content

Commit

Permalink
test: add test for random torrent file generator service
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Jul 31, 2023
1 parent 40c4df0 commit 4b6f25c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/services/torrent_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,45 @@ pub fn generate_random_torrent(id: Uuid) -> Torrent {

Torrent::from_new_torrent_info_request(torrent_info_request)
}

#[cfg(test)]
mod tests {
use serde_bytes::ByteBuf;
use uuid::Uuid;

use crate::models::torrent_file::{Torrent, TorrentInfo};
use crate::services::torrent_file::generate_random_torrent;

#[test]
fn it_should_generate_a_random_meta_info_file() {
let uuid = Uuid::parse_str("d6170378-2c14-4ccc-870d-2a8e15195e23").unwrap();

let torrent = generate_random_torrent(uuid);

let expected_torrent = Torrent {
info: TorrentInfo {
name: "file-d6170378-2c14-4ccc-870d-2a8e15195e23.txt".to_string(),
pieces: Some(ByteBuf::from(vec![
62, 231, 243, 51, 234, 165, 204, 209, 51, 132, 163, 133, 249, 50, 107, 46, 24, 15, 251, 32,
])),
piece_length: 16384,
md5sum: None,
length: Some(37),
files: None,
private: Some(0),
path: None,
root_hash: None,
},
announce: None,
announce_list: Some(vec![]),
creation_date: None,
comment: None,
created_by: None,
nodes: None,
encoding: None,
httpseeds: None,
};

assert_eq!(torrent, expected_torrent);
}
}

0 comments on commit 4b6f25c

Please sign in to comment.