From bd66b5239598e67a57487480df02b3abfae1b672 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Mon, 13 Jan 2025 16:09:01 +0000 Subject: [PATCH] Remove file reading in librqbit_core tests --- crates/librqbit_core/src/torrent_metainfo.rs | 37 ++++---------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/crates/librqbit_core/src/torrent_metainfo.rs b/crates/librqbit_core/src/torrent_metainfo.rs index c5b0ea05..da546663 100644 --- a/crates/librqbit_core/src/torrent_metainfo.rs +++ b/crates/librqbit_core/src/torrent_metainfo.rs @@ -413,47 +413,28 @@ where #[cfg(test)] mod tests { - use std::io::Read; - use bencode::BencodeValue; 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] fn test_deserialize_torrent_owned() { - let mut buf = Vec::new(); - std::fs::File::open(TORRENT_FILENAME) - .unwrap() - .read_to_end(&mut buf) - .unwrap(); - - let torrent: TorrentMetaV1Owned = torrent_from_bytes(&buf).unwrap(); + let torrent: TorrentMetaV1Owned = torrent_from_bytes(TORRENT_BYTES).unwrap(); dbg!(torrent); } #[test] fn test_deserialize_torrent_borrowed() { - let mut buf = Vec::new(); - std::fs::File::open(TORRENT_FILENAME) - .unwrap() - .read_to_end(&mut buf) - .unwrap(); - - let torrent: TorrentMetaV1Borrowed = torrent_from_bytes(&buf).unwrap(); + let torrent: TorrentMetaV1Borrowed = torrent_from_bytes(TORRENT_BYTES).unwrap(); dbg!(torrent); } #[test] fn test_deserialize_torrent_with_info_hash() { - let mut buf = Vec::new(); - std::fs::File::open(TORRENT_FILENAME) - .unwrap() - .read_to_end(&mut buf) - .unwrap(); - - let torrent: TorrentMetaV1Borrowed = torrent_from_bytes(&buf).unwrap(); + let torrent: TorrentMetaV1Borrowed = torrent_from_bytes(TORRENT_BYTES).unwrap(); assert_eq!( torrent.info_hash.as_string(), "64a980abe6e448226bb930ba061592e44c3781a1" @@ -462,13 +443,7 @@ mod tests { #[test] fn test_serialize_then_deserialize_bencode() { - let mut buf = Vec::new(); - std::fs::File::open(TORRENT_FILENAME) - .unwrap() - .read_to_end(&mut buf) - .unwrap(); - - let torrent: TorrentMetaV1Info = torrent_from_bytes(&buf).unwrap().info; + let torrent: TorrentMetaV1Info = torrent_from_bytes(TORRENT_BYTES).unwrap().info; let mut writer = Vec::new(); bencode::bencode_serialize_to_writer(&torrent, &mut writer).unwrap(); let deserialized = TorrentMetaV1Info::::deserialize(