Remove file reading in librqbit_core tests

This commit is contained in:
Igor Katson 2025-01-13 16:09:01 +00:00
parent c13268dd7b
commit bd66b52395
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5

View file

@ -413,47 +413,28 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::io::Read;
use bencode::BencodeValue; use bencode::BencodeValue;
use super::*; use super::*;
const TORRENT_FILENAME: &str = "../librqbit/resources/ubuntu-21.04-desktop-amd64.iso.torrent"; const TORRENT_BYTES: &[u8] =
include_bytes!("../../librqbit/resources/ubuntu-21.04-desktop-amd64.iso.torrent");
#[test] #[test]
fn test_deserialize_torrent_owned() { fn test_deserialize_torrent_owned() {
let mut buf = Vec::new(); let torrent: TorrentMetaV1Owned = torrent_from_bytes(TORRENT_BYTES).unwrap();
std::fs::File::open(TORRENT_FILENAME)
.unwrap()
.read_to_end(&mut buf)
.unwrap();
let torrent: TorrentMetaV1Owned = torrent_from_bytes(&buf).unwrap();
dbg!(torrent); dbg!(torrent);
} }
#[test] #[test]
fn test_deserialize_torrent_borrowed() { fn test_deserialize_torrent_borrowed() {
let mut buf = Vec::new(); let torrent: TorrentMetaV1Borrowed = torrent_from_bytes(TORRENT_BYTES).unwrap();
std::fs::File::open(TORRENT_FILENAME)
.unwrap()
.read_to_end(&mut buf)
.unwrap();
let torrent: TorrentMetaV1Borrowed = torrent_from_bytes(&buf).unwrap();
dbg!(torrent); dbg!(torrent);
} }
#[test] #[test]
fn test_deserialize_torrent_with_info_hash() { fn test_deserialize_torrent_with_info_hash() {
let mut buf = Vec::new(); let torrent: TorrentMetaV1Borrowed = torrent_from_bytes(TORRENT_BYTES).unwrap();
std::fs::File::open(TORRENT_FILENAME)
.unwrap()
.read_to_end(&mut buf)
.unwrap();
let torrent: TorrentMetaV1Borrowed = torrent_from_bytes(&buf).unwrap();
assert_eq!( assert_eq!(
torrent.info_hash.as_string(), torrent.info_hash.as_string(),
"64a980abe6e448226bb930ba061592e44c3781a1" "64a980abe6e448226bb930ba061592e44c3781a1"
@ -462,13 +443,7 @@ mod tests {
#[test] #[test]
fn test_serialize_then_deserialize_bencode() { fn test_serialize_then_deserialize_bencode() {
let mut buf = Vec::new(); let torrent: TorrentMetaV1Info<ByteBuf> = torrent_from_bytes(TORRENT_BYTES).unwrap().info;
std::fs::File::open(TORRENT_FILENAME)
.unwrap()
.read_to_end(&mut buf)
.unwrap();
let torrent: TorrentMetaV1Info<ByteBuf> = torrent_from_bytes(&buf).unwrap().info;
let mut writer = Vec::new(); let mut writer = Vec::new();
bencode::bencode_serialize_to_writer(&torrent, &mut writer).unwrap(); bencode::bencode_serialize_to_writer(&torrent, &mut writer).unwrap();
let deserialized = TorrentMetaV1Info::<ByteBuf>::deserialize( let deserialized = TorrentMetaV1Info::<ByteBuf>::deserialize(